Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Please help with my query...

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-12-07 : 21:40:23
Jason writes "Hi Sql Team.
I have a query which uses a CASE statement to find whether a field is empty or not. Ultimately I want to create a bar chart which shows "Reference Number Given" versus "Not Given" when messages are submitted via a html form. A typical ref_num is 444444xyz Here is the query:

SELECT Count(primary_key) SsrCount, Max(Count(primary_key)) MaxCount,
CASE
WHEN ref_num IS NULL THEN 0
ELSE 1
END
AS blnNumSubmitted
FROM tbl_messages
GROUP BY
CASE
WHEN ref_num IS NULL THEN 0
ELSE 1
END

The Count(primary_key) is to count the numbers and Max(Count.... is to find the highest value.

My questions are: is this efficient? is there a better/simpler way to do this?
I'm using SQL Server 7.0 and WinNT 4.0 sp4

Any help much appreciated!

Jason"
   

- Advertisement -