Select count() - Classic ASP - Access Database

Please take a look at the recordSet below. I get the correct value if I just run one of the Selects() at a  time.

This is a syntax issue.

Any help appreciated ;-)  

--------------------------------------------------------

strSQL = "(SELECT COUNT(*) As LevelOne FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class = cl.Cl_ID WHERE cl.Cl_WordLevel = 1 ),  " &_
             "(SELECT COUNT(*) As LevelTwo FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class = cl.Cl_ID WHERE cl.Cl_WordLevel = 2 ), " &_
             "(SELECT COUNT(*) As LevelThree FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class = cl.Cl_ID WHERE cl.Cl_WordLevel = 3 ),  " &_
             "(SELECT COUNT(*) As LevelZero FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class = cl.Cl_ID WHERE cl.Cl_WordLevel = 0 ) "
Set rsData = MyConn.Execute(strSQL)
If Not rsData.EOF Then
'LevelOneNums = rsData("LevelOne")
'LevelTwoNums = rsData("LevelTwo")
'LevelThreeNums = rsData("LevelThree")
'LevelZeroNums = rsData("LevelZero")
End If
LVL 5
Abiel de GrootDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PatHartmanCommented:
You would need to run each of these queries separately.  You can't stack queries in an SQL string and run them all at once.  There are two alternate solutions.   The best solution and the one that won't require maintenance should a different level be added is the following query which will return one row for each different value of WordLevel.

SELECT COUNT(*) As LevelCount, "Level-" & cl.Cl_WordLevel As Level   FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class  Group by "Level-" & cl.Cl_WordLevel;

If you want one row returned with a column for each level then use this:

Select Sum(IIf(cl.CL_Wordlevel = 0, 1, 0)) as LevelZero, Sum(IIf(cl.CL_Wordlevel = 1, 1, 0)) as LevelOne, Sum(IIf(cl.CL_Wordlevel = 2, 1, 0)) as LevelTwo, ....
FROM tbl_Students st INNER JOIN tbl_Classes cl ON st.Stu_Class;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Abiel de GrootDeveloperAuthor Commented:
Many thanks. ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.