Pages - Menu

2012年7月31日 星期二

Select Case 來將欄位NULL值轉為0




select a.item_no,(a.qty+case  b.qty when null then 0 else sum(b.io*b.qty) end )as 月底庫存數量
from  itmmbemt a left join itmmsum b on a.item_no=b.item_no and a.YYYYMM=b.YYYYmm
where a.YYYYMM='201206' and a.item_no='10010014'
group by a.item_no,a.qty,b.qty


select a.item_no,(a.qty+case when b.qty is null then 0 else sum(b.io*b.qty) end )as 月底庫存數量
from  itmmbemt a left join itmmsum b on a.item_no=b.item_no and a.YYYYMM=b.YYYYmm
where a.YYYYMM='201206' and a.item_no='10010014'
group by a.item_no,a.qty,b.qty

沒有留言:

張貼留言