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)
 returning 0

Author  Topic 

Scott
Posting Yak Master

145 Posts

Posted - 2002-12-17 : 03:00:58
I have a sql statement that is counting on a condition:
SELECT 'totbm' as [type], COUNT(*)as tot, cat from dbo.View_HR_PersonSummary WHERE
GENDER = 'Male'AND RACE = 'black'and cat = @pcat group by cat

however when the condition is not met, i require a 0 to be returned it the tot column, so that the record set is for all conditions.

any suggestions?

nr
SQLTeam MVY

12543 Posts

Posted - 2002-12-17 : 03:51:58
SELECT 'totbm' as [type],
sum(case when GENDER = 'Male'AND RACE = 'black'and cat = @pcat then 1 else 0 end) as tot,
cat
from dbo.View_HR_PersonSummary
group by cat


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -