Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqldba2k6
Posting Yak Master
176 Posts |
Posted - 2006-10-12 : 22:53:13
|
| I have a table with the following data:-- Prepare test dataDECLARE @Test TABLE (ID TINYINT, RCODE VARCHAR(10))INSERT @TestSELECT 101, 'A1' UNION ALLSELECT 102, 'A1' UNION ALLSELECT 101, 'A2' UNION ALLSELECT 102, 'A2' UNION ALLSELECT 113, 'A2' UNION ALLSELECT 120, 'A2' UNION ALLSELECT 101, 'A3' UNION ALLSELECT 102, 'A3' UNION ALLSELECT 108, 'A3' UNION ALLSELECT 124, 'A3' UNION ALLSELECT 102, 'A4' UNION ALLSELECT 102, 'A5' UNION ALLSELECT 106, 'A5' I need the below output with the queryid A1 A2 A3 A4 A5--- -- ---- --- --- ---101 A1 A2 A3 null null102 A1 A2 A3 A4 A5106 null null null null A5108 null null A3 null null 113 null A2 null null null120 null A2 null null null124 null null A3 null nullThanks for yur help in advance.. |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-10-12 : 23:01:59
|
| [code]select ID, max( case when RCODE = 'A1' then RCODE else null end) A1 , max( case when RCODE = 'A2' then RCODE else null end) A2 , max( case when RCODE = 'A3' then RCODE else null end) A3 , max( case when RCODE = 'A4' then RCODE else null end) A4 , max( case when RCODE = 'A5' then RCODE else null end) A5from @Testgroup by IDorder by ID[/code]CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|