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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Column to Rows

Author  Topic 

chriztoph
Posting Yak Master

184 Posts

Posted - 2012-07-09 : 03:56:10
Hi everyone,

Need help here.

how do i convert a column into rows?

sample data:
ID Value1 Value2 Value3
1 T0001 Desc 1000
2 T0002 test sample

prefered output:
Much better if you can give the script for this
ID Attribute Value
1 Value1 T0001
1 Value2 Desc
1 Value3 1000
2 Value1 T0002
2 Value2 test
2 Value3 sample

thanks in advance

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2012-07-09 : 04:35:06
try using the pivot function.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-09 : 09:48:02
it should be unpivot

SELECT *
FROM Table t
UNPIVOT (Value FOR Attribute IN ([Value1],[Value2],[Value3]))u


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2012-07-11 : 01:27:53
thanks visakh16.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-11 : 10:29:41
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -