Basic Example for PIVOT:
SELECT gid,
[1] AS cname1,
[2] AS Cname2,
[3] AS Cname3,
[4] AS Cname4,
[5] as Cname5
FROM
(SELECT gid,gpid,gpname,Name FROM test) s
PIVOT
(
MAX(Name)
FOR gname IN ([1],[2],[3],[4],[5])
) p
ORDER BY [gid]
GO
SELECT gid,
[1] AS cname1,
[2] AS Cname2,
[3] AS Cname3,
[4] AS Cname4,
[5] as Cname5
FROM
(SELECT gid,gpid,gpname,Name FROM test) s
PIVOT
(
MAX(Name)
FOR gname IN ([1],[2],[3],[4],[5])
) p
ORDER BY [gid]
GO
No comments:
Post a Comment