How to convert rows to columns using pivot
1
0
I Have table with data like this A|B|C|D|E| ---------- 100|ABC|OL|Decmber|100 100|ABC|OL|January|200 100|ABC|OL|February|290 100|DEF|OL|Decmber|260 100|DEF|OL|January|300 100|DEF|OL|February|360 200|ABC|OL|December|500 200|ABC|OL|January|600 200|ABC|OL|February|550 200|DEF|OL|December|570 200|DEF|OL|January|600 200|DEF|OL|February|680 ---------- I want the output should be A|B|C|December|January|February 100|ABC|OL|100|290|300 100|DEF|OL|200|260|360 200|ABC|OL|500|550|600 200|DEF|OL|600|570|680 As the values are dynamic so i have below query:- DECLARE @cols NVARCHAR(MAX), @query NVARCHAR(MAX); SET @cols = STUFF( ( SELECT Distinct ','+QUOTENAME(c.[D]) FROM #rolling c FOR XML PATH(''), TYPE ...