超奇怪的問題?數值類SUM後,返回的結果還是數據,但為什麼不能計算?
select T01 as 品號,T02 as 品名,T03 as 尺寸,T04 as 上月結存,isnull(X01,0) as 本月入庫,isnull(X02,0) as 本月出庫,isnull(X03,0) as 本月調整,isnull((T04+X01-X02+X03),0) as 結存數 from
(
select * from
(
/*庫別中品號資料*/
select TAICON_TA.TA001 as T01,TAICON_TA.TA002 as T02,TAICON_TA.TA006 as T03
from TAICON_TA,TAICON_TB,INPUT_A,INPUT_B
where INPUT_B.B002 =TAICON_TA.TA001 and TAICON_TA.TA006=TAICON_TB.TB002 and TAICON_TB.TB003= '5 ' and INPUT_A.A001=INPUT_B.B001 and INPUT_A.A012=INPUT_B.B006 and INPUT_A.A002= '1 ' and ( INPUT_A.A014= '[2]107待處理品倉 ')
group by TAICON_TA.TA006,TAICON_TA.TA001,TAICON_TA.TA002,TAICON_TB.TB001
/*order by TAICON_TB.TB001,TAICON_TA.TA001*/
)a left join
/*上月結存*/
( select INPUT_B.B002,isnull((SUM(INPUT_B.B005)-SUM(INPUT_B.B007)+SUM(INPUT_B.B009)),0) as T04
from INPUT_A,INPUT_B
where INPUT_A.A001=INPUT_B.B001 and INPUT_A.A012=INPUT_B.B006 and INPUT_A.A002= '1 ' and INPUT_A.A008 < '2007.03.00 '
group by INPUT_B.B002
)
b on a.T01=b.B002
)c left join
(
/*本月結存*/
select INPUT_B.B002,isnull(SUM(INPUT_B.B005),0) as X01,isnull(SUM(INPUT_B.B007),0) AS X02,isnull(SUM(INPUT_B.B009),0) as X03,isnull((SUM(INPUT_B.B005)-SUM(INPUT_B.B007)+SUM(INPUT_B.B009)),0) as X04
from INPUT_A,INPUT_B
where INPUT_A.A001=INPUT_B.B001 and INPUT_A.A012=INPUT_B.B006 and INPUT_A.A002= '1 ' and INPUT_A.A008 like '2007.03.% '
group by INPUT_B.B002
)d on c.T01= d.B002
where ((T04+X01+X02+X03+X04) <> 0)
order by T01
/*where ((T04+X01+X02+X03+X04) <> 0)這一句的作用是不顯示T04,X01,X02,X03,X04都為0或Null的結果.但T04有的值不為0的也給排除了,奇怪.
如下面沒有加Where語句後顯示的結果%/
品 號 品 名 尺 寸 上月結存 本月入庫(全) 本月出庫(全) 本月調整(全) 結存數
TAQ2D151MA18250LL3 TAQ 200V 150uF ML 18x25 990 0 0 0 990
TAQ2D331MK1835MLL3 TAQ 200V 330uF ML 18x35.5 0 125,378 118,567 0 6,811
TAQ2D470MA12200LL5 TAQ 200V 47uF ML 12.5x20 336 0 0 0 336
TAQ2D471MK18400LL3 TAQ 200V 470uF ML 18x40 11,071 81,726 88,126 0 4,671
TAQ2D471YK18400LL3 TAQ 200V 470uF YL 18x40 0 3,105 2,400 0 705
TAQ2G100MK1012MLL3 TAQ 400V 10uF ML 10x12.5 206,297 0 0 0 206,297
TAQ2G100MK10160RC3 TAQ 400V 10uF MR 10x16 97,963 0 0 0 97,963
TAQ2G101MK1631MLL3 TAQ 400V 100uF ML 16x31.5 2,723 11,491 0 0 14,214
/*加了where ((T04+X01+X02+X03+X04)