Author |
Topic |
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-29 : 11:44:04
|
Hi, i have declared the @DT5, @DT6 variables.In the below query, I am still getting NULL values in Last_year_sales column.SELECT c.DEP_DESCR as Department, SUM(ISNULL(SLS_AMT, 0)) as Last_year_SalesFROM FrontOff.dbo.DAY_PLU_SALES JOIN FrontOff.dbo.PLU B ON DAY_PLU_SALES.ITM_ID = B.ITM_IDleft JOIN FrontOff.dbo.DEP c ONb.STR_HIER_ID=c.STR_HIER_IDWHERE DT > @DT5AND DT < @DT6GROUP BY c.DEP_DESCRORDER BY c.DEP_DESCR.Regards,SushantDBAVirgin Islands(U.K) |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-02-29 : 11:56:16
|
Where is SLS_AMT coming from? Is it from DEP? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-29 : 12:06:19
|
quote: Originally posted by webfred Where is SLS_AMT coming from? Is it from DEP? No, you're never too old to Yak'n'Roll if you're too young to die.
from DAY_PLU_SALESRegards,SushantDBAVirgin Islands(U.K) |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-02-29 : 12:14:22
|
try to put the ISNULL to the outer side like this:ISNULL(SUM(SLS_AMT),0) as Last_year_Sales No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
X002548
Not Just a Number
15586 Posts |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-29 : 14:25:04
|
Ok, I found the faults...If iam doing a left join, so the rows whcih are left out, thery will be NULL...So, how to put them as 0 instead of NULL.Regards,SushantDBAVirgin Islands(U.K) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-29 : 15:38:18
|
COALESCE the SUM don't SUM the COALESCE. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-03-01 : 07:53:31
|
quote: Originally posted by Lamprey COALESCE the SUM don't SUM the COALESCE.
That was it!Thanks to all.Regards,SushantDBAVirgin Islands(U.K) |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-03-01 : 08:53:54
|
quote: Originally posted by webfred try to put the ISNULL to the outer side like this:ISNULL(SUM(SLS_AMT),0) as Last_year_Sales No, you're never too old to Yak'n'Roll if you're too young to die.
That was it... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-03-01 : 13:47:53
|
quote: Originally posted by webfred
quote: Originally posted by webfred try to put the ISNULL to the outer side like this:ISNULL(SUM(SLS_AMT),0) as Last_year_Sales No, you're never too old to Yak'n'Roll if you're too young to die.
That was it... No, you're never too old to Yak'n'Roll if you're too young to die.
that I tried, but didn't work ...Thanks.Regards,SushantDBAVirgin Islands(U.K) |
 |
|
|