Can multi queries be done in ASP pages?

L

Lord Merlin

The following statement works fine in SQL Query Analyser: SELECT count(*) as
a from NEWUSERS WHERE activated='Y'; SELECT count(*) as b from NEWUSERS
WHERE activated='N' -- It returns two values, yet when I have it in a .asp
file, it only displays the first value. Is there anyway around this, without
making two connections to the DB, and running two seperate queries?

--

Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
 
W

William Morris

Sure. Assuming your recordset variable is "rs" then try this:

dim firstvalue, secondvalue
firstvalue = rs("a")
set rs = rs.nextRecordset
secondvalue = rs("b")
rs.close
set rs = nothing

- Wm
 
B

Bob Barrows [MVP]

Lord said:
The following statement works fine in SQL Query Analyser: SELECT
count(*) as a from NEWUSERS WHERE activated='Y'; SELECT count(*) as b
from NEWUSERS WHERE activated='N' -- It returns two values, yet when
I have it in a .asp file, it only displays the first value. Is there
anyway around this, without making two connections to the DB, and
running two seperate queries?

Why not combine them into a single query?

SELECT activated,Count(*) from NEWUSERS
GROUP BY activated

Bob Barrows
 
A

Aaron Bertrand - MVP

Not that this is a deterrent from your method, but I would bet that
activated allows NULLs, so you might want to add WHERE activated IN ('Y',
'N') or WHERE activated IS NOT NULL or something along those lines. Or,
don't allow NULLs in the column in the first place. ;-)

(Otherwise, you will get three rows in your resultset.)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top