I tried to convert the (null) values with 0 (zeros) output in PIVOT function but have no success.
Below is the table and the syntax I've tried:
SELECT CLASS, [AZ], [CA], [TX] FROM #TEMP PIVOT (SUM(DATA) FOR STATE IN ([AZ], [CA], [TX])) AS PVT ORDER BY CLASS CLASS AZ CA TX RICE 10 4 (null) COIN 30 3 2 VEGIE (null) (null) 9
I tried to use the ISNULL
but did not work.
PIVOT SUM(ISNULL(DATA,0)) AS QTY
What syntax do I need to use?
You can use isnull or coalesce to substitute a 0 for null values.
To do that just right click and select “PivotTable Options” under “Format for empty cells” put a “0”and then just click OK. And now you can see that the empty cells are showing a “0”.
Null values are replaced with mean/median.
SELECT CLASS, isnull([AZ],0), isnull([CA],0), isnull([TX],0) FROM #TEMP PIVOT (SUM(DATA) FOR STATE IN ([AZ], [CA], [TX])) AS PVT ORDER BY CLASS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With