1SELECT *
2FROM (SELECT YEAR(SalesDate) [Year],
3 DATENAME(MONTH, SalesDate) [Month],
4 COUNT(1) [Sales Count]
5 FROM #Sales
6 GROUP BY YEAR(SalesDate),
7 DATENAME(MONTH, SalesDate)) AS MontlySalesData
8PIVOT( SUM([Sales Count])
9 FOR Month IN ([January],[February],[March],[April],[May],
10 [June],[July],[August],[September],[October],[November],
11 [December])) AS MNamePivot
12