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 SQL SERVER 2000

Author  Topic 

on7june
Starting Member

41 Posts

Posted - 2008-11-10 : 05:55:30
How to transpose rows in SQL Server 2000.

TblName : Prod

Months Value
----------------
Jan 1000
Feb 6000
Mar 5000
Apr 3000
. .
. .
. .
. .
Dec 2000

I need a select statement which should transpose this data as follows.

Months Jan Feb Mar Apr . . . . Dec
Value 1000 6000 5000 3000 2000



Sarvan

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-10 : 05:59:38
Read about Cross-ta Reports in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-10 : 06:05:15
[code]SELECT 'Values' AS Month,
MAX(CASE WHEN Month='Jan' THEN Value ELSE NULL END) AS Jan,
MAX(CASE WHEN Month='Feb' THEN Value ELSE NULL END) AS Feb,
MAX(CASE WHEN Month='Mar' THEN Value ELSE NULL END) AS Mar,
...
MAX(CASE WHEN Month='Dec' THEN Value ELSE NULL END) AS Dec
FROM Table[/code]
Go to Top of Page

on7june
Starting Member

41 Posts

Posted - 2008-11-10 : 08:06:01
Thanks a lot madhi/visakh for the quick turn around. Its working now for me.

Sarvan
Go to Top of Page
   

- Advertisement -