• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

asp w/ javascript & sql question

gtbuzz

Senior member
maybe i'm looking overlooking something plainly obvious but maybe someone can point me in the right direction. in a nutsell i'm trying to find out how many cells in column contain a certain value using the following sql statement:

SQL = SELECT COUNT(column_name) FROM table_name WHERE column_name = 'VALUE';

I've tried the command in access and it works fine. What i'm doing now is passing on a certain value to a javascript function that has that sql command embedded ie

count_function(VALUE);

how do i get it to return whatever value sql server spits out? i was originally thinking something like

my_number = connection_name.execute(SQL)

but that doesn't seem to work real well. Any clues? Thanks!
 
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT COUNT(column_name) AS num FROM table_name WHERE column_name = 'VALUE'", <name of connection>

my_number = rs("num")

set rs = nothing
rs.close
<name of connection>.close

That's the asp part of it. Getting over to the javascript is something I've never had to do so I can't help you there.
 
thanks for the reply. i ended up figuring it out. kinda pisses me off that microsoft's 'jscript' handles stuff a little differently than javascript does. go fig. made my life a helluva lot harder!

anyway,

lets say we have a connection name 'connection_name'. using the previous sql statement, i can do

connection_name.execute(SQL);

if i did

my_number = connection_name.execute(SQL);

i can display the number returned from sql server as follows:

Response.Write(my_number(0));
my_number.close();

for some reason or another, jscript doesn't support the tostring() object like javascript does. whatever. hope this helps someone!
 
of course it does. you just have to have a number-type object existing prior to executing .tostring() on it!
picking up where both of you guys left off without display part, considering you have gotten the value for my_number one way or the other:

my_number=.....%>

<html>
<head>
<script language=javascript>
var MyNumber = new Number(<%=my_number%>)
var MyString = MyNumber.tostring()
....


</script>
 
Back
Top