Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2008-08-07 : 00:16:50
|
I had to adjust my query to make NULL become 0. Till now, still struggle.This is my tabletITemItmLocation | ItmCode | ItmDsc | ItmPrc | ItmMax--------------------------------------------------------------------KU | 206622 | YES | 7.2 | 3KU | 221694 | Nalgene | 4.2 | 4KU | 226699 | JOKI | 8.1 | 3KU | 231610 | BUL | 7.70 | 3KU | 231621 | TAT | 5.10 | 3............tOrderOrdNo | OrdEmpNo | OrdDte | OrdLocation | OrdItm | OrdQty | OrdAmt | OrdProcceesed | OrdDlv---------------------------------------------------------------------------------------------------------------------107848 | 16005 | 6/22/2008 | KU |206622 | 2 | 14.4 | 6/22/2008 | 2107902 | 16005 | 6/22/2008 | KU |221694 | 3 | 12.6 | 6/22/2008 | 3107311 | 16005 | 6/22/2008 | KU |226699 | 2 | 16.2 | 6/22/2008 | 2............************************************************************************************************SELECT Itm, ItmDsc, ItmPrc, ItmMax, OrdQty=SUM(OrdQty), OrdDlv=SUM(OrdDlv), OrdQuotaLeft=CASE WHEN SUM(OrdQty) IS NULL THEN ItmMax ELSE ItmMax - SUM(OrdQty) END FROM tmItm LEFT OUTER JOIN Torder ON Itm = OrdItm AND OrdEmpNo = '16005' AND month(OrdDte) = month(GetDate()) AND year(OrdDte) = year(GetDate()) WHERE ItmWhs = 'KU'GROUP BY Itm, ItmDsc, ItmPrc, ItmMax, OrdItmItm |ItmDsc |ItmPrc | ItmMax | OrdQty | OrdDlv |OrdQuotaLeft------------------------------------------------------------------------------------206622 YES 7.2 3 2 2 1221694 Nalgene 4.2 4 3 3 1226699 JOKI 8.1 3 2 2 1231610 BUL 7.7 3 NULL NULL 3231610 TAT 5.1 3 NULL NULL 3......How to adjust my above query to make it NULL become 0, so the result becomeItm |ItmDsc |ItmPrc | ItmMax | OrdQty | OrdDlv |OrdQuotaLeft------------------------------------------------------------------------------------206622 YES 7.2 3 2 2 1221694 Nalgene 4.2 4 3 3 1226699 JOKI 8.1 3 2 2 1231610 BUL 7.7 3 0 0 3231610 TAT 5.1 3 0 0 3...... |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-07 : 02:44:53
|
look at coalesce() and isnull() in books onlineEm |
 |
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2008-08-07 : 04:03:53
|
tq very much for the info :) |
 |
|
|
|
|
|
|