Created
August 14, 2014 04:35
-
-
Save AsifMushtaq/5836b325ed646f5b9fae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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