Click to See Complete Forum and Search --> : getting SQL function results from a RS


Nicodemas
06-11-2003, 09:47 AM
My SQL Statement:

strSQL = "SELECT COUNT(QuestionID) FROM tblQuestions WHERE PollId = "& intPoll_ID


How do I write out that result? I tried to put it into a recordset and then write it out like so:


response.write rsQuestionID("QuestionID")


but that doesn't work... what should I do to grab that value?

khaki
06-11-2003, 11:43 AM
hi Rob...

give this a try:

strSQL = "SELECT COUNT(QuestionID) AS theIDcnt FROM tblQuestions WHERE PollId = "& intPoll_ID

and retrieve it like this:

<%response.write theIDcnt %>

let me know if that works for you...

;) k

Ribeyed
06-11-2003, 12:26 PM
Hi,
just to add to what Khaki has said, you may also be getting an error if the sql statment returns empty. I suggest the following:



strSQL = "SELECT COUNT(QuestionID) AS theIDcnt FROM tblQuestions WHERE PollId = "& intPoll_ID
set RS = DataCOnnection(strSQL)

if not RS.EOF then
response.write theIDcnt
else
response.write "0"
end if

khaki
06-11-2003, 12:38 PM
ah.... yes....
brilliant !!!

(will now never reveal her own nonsensical code for handling zero records :rolleyes: ) ...
;) k

Nicodemas
06-12-2003, 08:03 AM
Son of gun, Khaki.... it worked!

Thanks much. I (obviously) didn't even consider aliasing.