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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Pivot? rows to columns?

Author  Topic 

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2009-10-08 : 06:41:51
Hi Guys,

I have a table which looks roughly like this
(sorry for the formatting)

0-10% 20-30% 30-40%
Loans 1455 43 83
Value 324343 893849 93738

and I need it to be like this:

0-10% 1455 324343
20-30% 43 893849
30-40% 83 93738

i.e the values in the rows as values in columns and the column names as values..

Assistance would be greatly appreciated!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-10-08 : 07:06:07
That's UNPIVOT.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2009-10-08 : 07:30:47
would you be able to give me an example on how I can apply it to the above sample? I've looked at forums, but never seem to get my head around how to script it... :(
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2009-10-09 : 11:38:38
Can i do this without an ID field??

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-09 : 12:50:31
http://wiki.lessthandot.com/index.php/Column_To_Row_(UNPIVOT)
Go to Top of Page
   

- Advertisement -