日期:2014-05-18  浏览次数:20687 次

sql server Case语句块
SQL code
select sum(jqquantity-sjqquantity-yjqquantity),sum(jqcost-sjqcost-HDBJE),sum(jqquantity-sjqquantity),sum(jqcost-sjqcost),sum((jqquantity-jqquantity)-(sjqquantity-jqquantity)),sum(HRK) as HRK,sum(HRKJE) as HRKJE,sum(HGYLRK) as HGYLRK,sum(HGYLRKJE) as HGYLRKJE,sum(HFLRK) as HFLRK,
sum(HFLRKJE) as HFLRKJE,sum(HYCRK) as HYCRK,sum(HYCRKJE) as HYCRKJE,sum(HCK) as HCK,sum(HCKJE) as HCKJE,sum(HGYLCK) as HGYLCK,sum(HGYLCKJE) as HGYLCKJE,
sum(HFLCK) as HFLCK,sum(HFLCKJE) as HFLCKJE,sum(HDB) as HDB,sum(HDBJE) as HDBJE,sum(HYCCK) as HYCCK,sum(HYCCKJE) as HYCCKJE,
sum(WRK) as WRK,sum(WRKJE) as WRKJE,sum(WGYLRK) as WGYLRK,sum(WGYLRKJE) as WGYLRKJE,sum(WFLRK) as WFLRK,sum(WFLRKJE) as WFLRKJE,sum(WYCRK) as WYCRK,
sum(WYCRKJE) as WYCRKJE,sum(WCK) as WCK,sum(WCKJE) as WCKJE,sum(WGYLCK) as WGYLCK,sum(WGYLCKJE) as WGYLCKJE,sum(WFLCK) as WFLCK,sum(WFLCKJE) as WFLCKJE,
sum(WDB) as WDB,sum(WDBJE) as WDBJE,sum(WYCCK) as WYCCK,sum(WYCCKJE) as WYCCKJE from @t 


sum可能是NULL 如果等于NULL 我想让它是0 我用case语句块怎么加?

------解决方案--------------------
CASE NUM WHEN NULL THEN 0 ELSE NUM END
------解决方案--------------------
或者isnull(num,0)--这个更简单点
------解决方案--------------------
直接用 isnull()不就好了
------解决方案--------------------
sum(jqquantity-sjqquantity-yjqquantity)

-->

sum(isnull(jqquantity,0)-isnull(sjqquantity,0)-isnull(yjqquantity,0))

其他类似