Reputation: 3492
How to get monthly report in Pivot format in SQL?
I am trying to generate a pivot format of monthly report in ..
Upvotes: 1
Views: 53
Reputation: 65408
You can use conditional aggregation
select SourceID,
sum(case when month(FileReceivedDate)= 1 then 1 else 0 end ) as Jan,
sum(case when month(FileReceivedDate)= 2 then 1 else 0 end ) as Feb,
sum(case when month(FileReceivedDate)= 3 then 1 else 0 end ) as Mar,
sum(case when month(FileReceivedDate)= 4 then 1 else 0 end ) as Apr
from tab
group by SourceId
Upvotes: 1