change date in pivot table to month in sql server

Solutions on MaxInterview for change date in pivot table to month in sql server by the best coders in the world

showing results for - "change date in pivot table to month in sql server"
Matis
10 Jan 2018
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