ID Name 1 aaa 1 bbb 1 ccc 2 xxx 2 yyy 2 zzz
ID Name Name2 Name3 1 aaa bbb ccc 2 xxx yyy zzz
SELECT id, [1] as name1, [2] as name2, [3] as name3 FROM ( SELECT id, [name], rank() over (partition by id order by [name]) AS RANK FROM temp ) pvt PIVOT ( MAX([NAME]) FOR RANK IN ([1],[2],[3]) ) A
SELECT [1] AS Name1, [2] AS Mame2, [3] AS Name3 FROM ( SELECT [name], RANK() OVER (PARTITION BY id ORDER BY [name]) AS RowNo FROM temp ) DT PIVOT(MAX([name]) FOR RowNo IN ([1],[2],[3])) PVT
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)