select *
from
(
select type,SUM(ISNULL(amount,0)) AS amount,month(date) as date from tbl_cashmaster
where date between '2016/12/31' and '2017/12/31'
group by type,month(date)
) src
pivot
(
sum(amount)
for date in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) piv;
How can I get zero in null value columns? The above query is returning null's, where there is no data. What changes do I need to make in this to get 0
instead of null
?
Best Answer
If you have a fixed number of pivot points, you could do what McNets suggests in the comments:
For a variable number of pivot points, you can use dynamic
SQL
- here is an example:Note the references to
colCoalesceNull