[thelist] case statement catch-all? MSSQL

Mark Rees mrees at itsagoodprice.com
Wed Aug 24 09:54:41 CDT 2005


> Jay Blanchard wrote:
> 
> > Perhaps a crosstab query; (bull-in-the-china-shop-method)
> > 
> > SELECT 

Rewrite it like this for MSSQL

SUM(CASE WHEN CT='C' THEN 1 ELSE 0 END) AS 'CT',

> > SUM(IF(CT = 'C', 1, 0)) AS "CT",
> > SUM(IF(PA = 'P', 1, 0)) AS "PA",
> > SUM(IF(TX = 'T', 1, 0)) AS "TX",
> > SUM((IF(CT = 'C', 1, 0)))+IF(PA = 'P', 1, 0))+IF(TX = 'T', 1, 0))) AS
> > "ALL"
> > FROM table
> > GROUP BY whatever you see necessary
> 
> 
> Thanks, but this fails miserably.  syntax Errors on the IF's, and every 
> comma for the 1,0.
> 




More information about the thelist mailing list