[thelist] case statement catch-all? MSSQL

Jay Blanchard jay.blanchard at niicommunications.com
Wed Aug 24 10:59:01 CDT 2005


[snip]
The results, as you have coded the query, will come back spanning three
rows
because of the GROUP BY clause. 

Drop the group by, and you should be closer to what you want:

SELECT
	SUM(case site when 'B' then 1 else 0 end) AS 'Bristol, CT',	
	SUM(case site when 'L' then 1 else 0 end) AS 'Lock Haven, PA',
	SUM(case site when 'T' then 1 else 0 end) AS 'Brownsville, TX',
	SUM(case WHEN site IN ('B', 'L', 'T') then 1 else 0 end) AS
'ALL'
from table

Also, adding null to anything is null, so replace null with 0.
[/snip]

*smacks forhead* Drat! I forgot that no group by is needed for this.....


More information about the thelist mailing list