Returning several COUNT results from one ASP SQL statement

Posted by user89691 on Stack Overflow See other posts from Stack Overflow or by user89691
Published on 2010-05-18T05:22:31Z Indexed on 2010/05/18 5:30 UTC
Read the original article Hit count: 333

Filed under:
|
|

Say I have a table like this:

Field1  Field2  Field3  Field4
fred    tom     fred    harry 
tom             tom
dick    harry
harry           

and I want to determine what proportion of it has been completed for each field.

I can execute:

SELECT COUNT (Field1) WHERE (Field1 <> '') AS Field1Count      
SELECT COUNT (Field2) WHERE (Field2 <> '') AS Field2Count
SELECT COUNT (Field3) WHERE (Field3 <> '') AS Field3Count      
SELECT COUNT (Field4) WHERE (Field4 <> '') AS Field4Count  

Is it possible to roll up these separate SQL statements into one that will return the 4 results in one hit? Is there any performance advantage to doing so (given that the number of columns and rows may be quite large in practice)?

© Stack Overflow or respective owner

Related posts about asp-classic

Related posts about sql