我正在使用這裏顯示的查詢來總結財務目標第一條語句(expd)正在工作正常,它顯示的總和在socode
不等於29和42。但是 第二個陳述我只想得到總和socode = 42
和29和20,但它給出0.00值,而29和42有它自己的價值。如何使用SQL case語句獲取總和值
select
isnull(CONVERT(DECIMAL(10, 2),
SUM(CASE WHEN SoCode <> 42 and SoCode <> 29 and SoCode <> 20
THEN (Financialtarget)/100000 ELSE 0 END)), 0) as expd,
isnull(CONVERT(DECIMAL(10, 2),
SUM(CASE WHEN (SoCode = 29) and (SoCode = 42)
THEN (Financialtarget)/100000 ELSE 0 END)), 0) as expd1
from
MPR
where
month <= 7
and mpryear = '2014-15'
and Division = '12'
感謝
請格式化代碼。 – artm 2014-10-04 11:16:03