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)
 Convert Rows To Columns

Author  Topic 

DesiGuju
Starting Member

12 Posts

Posted - 2006-05-01 : 11:07:05
Good Morning Everyone,

I'm trying to convert rows to columns and can't figure out what's best way to do it.

This is what i have right now

ID Jan Feb March .......Dec
1 20 25 55
2 34 53 03

This is what i want

ID Month Value
1 1 20
1 2 25
2 1 34
2 2 53

Please help

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-05-01 : 11:25:34
Actually, you are trying to convert columns to rows...
select	ID,
1,
Jan as Value
from [YourTable]
UNION
select ID,
2,
Feb as Value
from [YourTable]
UNION
.
.
.
select ID,
12,
Dec as Value
from [YourTable]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-02 : 02:06:07
Also make sure the table is normalised
http://www.datamodel.org/NormalizationRules.html

Madhivanan

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

- Advertisement -