Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I am not getting how to write pivot query....My requirement is as followsSelect * from table where ID = '555'ID Col1 Col2 Col3555 123 456 67I want result as followsID 555Col1 123Col2 456 Col3 67G. Satish
Nageswar9
Aged Yak Warrior
600 Posts
Posted - 2009-02-17 : 01:40:18
declare @temp table ( ID INT,Col1 int,Col2 int, Col3 int)insert into @tempselect 555, 123, 456, 67select string,valuefrom (select * from @temp) punpivot ( value for string in (id,col1,col2,col3) ) as p2
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-02-17 : 03:03:31
or just use
SELECT ID,ColFROM(SELECT ID, Col1 AS ColFROM TableWHERE ID=555UNION ALLSELECT ID, Col2 FROM TableWHERE ID=555UNION ALLSELECT ID, Col3 FROM TableWHERE ID=555)t