Click to See Complete Forum and Search --> : SQL Output w/Count Question


theflyingminst
03-01-2009, 07:35 PM
Hi I am querying a database to output a column and it's unique/distinct count in a drop down.

Through some research this is what I've got so far. I was wondering if anyone had any ideas how I would be able to output these values in the way formerly described.

<%

Set oRs=Server.CreateObject("adodb.recordset")
strSQL = "SELECT distinct column, count(column) from table group by column"
oRs.Open strSQL, conn,3,3
count=oRs.recordcount

Do while not oRs.EOF
if qvar = oRs("column") then
Response.Write "<OPTION VALUE = '" & oRs("column") & "' SELECTED>"
Response.Write oRs("column") & " (" & count & ")</Option>"
orf_make = oRs("Make")
oRs.MoveNext
else

Response.Write "<OPTION VALUE = '" & oRs ("Column") & "'>"
Response.Write oRs("Column") & " (" & count & ")</Option>"
oRs.MoveNext
end if
loop

%>

Thank you

zahidraf
03-02-2009, 01:06 AM
When you fetch records use



While not Rs.eof

combo="<option ='Rs("value")'>Rs("value")</option>"


Rs.movenext

Wend


technology news (http://www.zahipedia.com)



hopes it helps

theflyingminst
03-02-2009, 08:53 AM
Cool, I'll give that a shot. Thanks!

theflyingminst
03-02-2009, 09:34 AM
Just tested it, that was it. Thanks so much!

zahidraf
03-04-2009, 01:08 AM
welcome and great to know it is working .

http://www.zahipedia.com