Wednesday, January 28, 2015

How to use PIVOT for varchar field


select name, [1] as PersonType,[2] as PersonType2,[3] as PersonType3,[4] as PersonType4,[5] as PersonType5
from (select *, row_number() Over(Partition by name Order by PersonType) rn from @MyTable) src Pivot (max(PersonType) for rn in ([1],[2],[3],[4],[5])) pvt


No comments:

Post a Comment