Hello:

I have a table where a column called ActiveStatus (of datatype 'bit') I am trying to run a query on may contain values Boolean values or NULL. Which means, if there are 10 rows in the table, a likely scenario would have 5 NULLs, 2 FALSEs, and 3 TRUEs.

Another possible case would be where there are 5 FALSEs, and 5 NULLs. i.e. No TRUEs.

I am trying to get the number of rows for each ActiveStatus type using a query like below:

SELECT	   COUNT(ActiveStatus)
FROM	   tblUserData
GROUP BY   ActiveStatus

I am then using this query to display the data using a server-side language by essentially using something like:
#NULLs: Display value in Row 1 of the query
#FALSEs: Display value in Row 2 of the query
#TRUEs: Display value in Row 3 of the query

Is this the best way to achieve what I am trying to? Here's why I ask:
The number of different types of values of the ActiveStatus columns can vary - sometimes TRUE, FALSE, and NULL; other times only TRUE, and NULL; still other times only TRUE, and FALSE and so on. Therefore, there is a possibility that my front-end script might bomb because there may not *be* a Row 3 to display.

What's the best way to get this done?

Hope I was clear about my problem.

Thanks!

Make the query

SELECT   ActiveStatus, Count(ActiveStatus)
FROM     tblUserData
GROUP BY ActiveStatus

Your front end script can then get which status the row is and how many times it occurs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.