Skip to content

Instantly share code, notes, and snippets.

@AsifMushtaq
Created August 14, 2014 04:35
Show Gist options
  • Save AsifMushtaq/5836b325ed646f5b9fae to your computer and use it in GitHub Desktop.
Save AsifMushtaq/5836b325ed646f5b9fae to your computer and use it in GitHub Desktop.
CREATE TABLE #t ( id int, Rscd varchar(10),Accd varchar(10),position int)
INSERT INTO #t Values (10,'A','B',1)
INSERT INTO #t Values (10,'C','D',2)
select id, [1], [2], [11], [12]
from
(
select id, col, value
from #t
cross apply
(
select rscd, position union all
select Accd, position + 10
) c (value, col)
) d
pivot
(
max(value)
for col in ([1], [2], [11], [12])
) piv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment