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 |
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2014-01-22 : 06:14:14
|
Dear All, I have a query, where i have a table where two columns is there.I want to convert first column records in Column header and second column records would come under that header.Col1 Col2 FirstName Ajay LastName Nath DOB 25/08/1981 Gender Male Output FirstName LastName DOB GenderAjay Nath 25/08/1981 Male Please help me |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-01-22 : 06:42:03
|
[code]with aCTEAS ( select 'FirstName' as Col1, 'Ajay' as Col2 union all select 'LastName', 'Nath' union all select 'DOB', '25/08/1981' union all select 'Gender' ,'Male' ) select *from aCTE Pivot( max(col2) FOR col1 in ([FirstName],[LastName],[DOB],[Gender])) AS x; [/code]Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mutsabinWeb |
|
|
|
|
|