Month wise total count and return zero if month data is not present?
I have small doubt in SQL. Please tell me how to display month-wise data to solve this issue in the SQL server.
Answers (1)
Add AnswerTry below query
SELECT [1] AS January, [2] AS February, [3] AS March, [4] AS April, [5] AS May, [6] AS June, [7] AS July, [8] AS August, [9] AS September, [10] AS October, [11] AS November, [12] AS December FROM (Select CreatedDate,MONTH(CreatedDate) as TMonth from PostMasters where YEAR(CreatedDate) = '2022') source PIVOT ( count(CreatedDate) FOR TMonth IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] ) ) AS pvtMonth
Thanks