0

i want to avoid null values and get zero when no monthly sales in each month

 SELECT * FROM 
 (
    SELECT DATENAME(MONTH, doa) [Month], sum(1) [Sales Count]
    From crime
    GROUP BY YEAR(doa),DATENAME(MONTH, doa)
 ) AS MontlySalesData 
 PIVOT
 ( 
   sum([Sales Count])  FOR Month 
   IN 
   (
     [January],[February],[March],[April],[May],[June],[July],
     [August],[September],[October],[November],[December]
    )
  ) AS MNamePivot  
Taryn
  • 242,637
  • 56
  • 362
  • 405
samjad ps
  • 45
  • 5
  • You can use the `ISNULL()` function – Nadeem_MK Sep 22 '14 at 13:40
  • Instead of using `SELECT *` in the final select, you'll need to replace the `null` with zero for each column - `select isnull(january, 0) as january...` – Taryn Sep 22 '14 at 13:42
  • 1
    You asked this exact question earlier. What was wrong with the answers ? – t-clausen.dk Sep 22 '14 at 13:51
  • [replace null values in sql pivot](http://stackoverflow.com/questions/3297132/replace-null-values-in-sql-pivot); or [How to replace (null) values with 0 output in PIVOT](http://stackoverflow.com/questions/12322342/how-to-replace-null-values-with-0-output-in-pivot) – Bolu Sep 22 '14 at 13:55
  • the query was wrong that i posted.but iwas was unable to edit it for 90mintes – samjad ps Sep 22 '14 at 14:02
  • thank u every one for helping me – samjad ps Sep 22 '14 at 14:05

1 Answers1

-3

mb you need to use ifnull()? http://www.smallsql.de/doc/sql-functions/system/ifnull.html