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 2000 Forums
 Transact-SQL (2000)
 Transpose Rows in to Columns

Author  Topic 

shabad
Starting Member

9 Posts

Posted - 2009-04-17 : 13:22:36
Hi

I need to transpose data in Sql 2000, can some one help me

Eg:
Item cp amnt
A R1 10
A R2 10
B R1 4
B R2 5

I need this to be formatted like

Item R1 R2
A 10 10
B 4 5

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-17 : 13:46:30
[code]SELECT Item,
MAX(CASE WHEN cp='R1' THEN amnt ELSE NULL END) AS R1,
MAX(CASE WHEN cp='R2' THEN amnt ELSE NULL END) AS R2
FROM table
GROUP BY Item
[/code]
Go to Top of Page
   

- Advertisement -