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 2005 Forums
 Transact-SQL (2005)
 Help Rows into Column

Author  Topic 

rajukurian
Starting Member

8 Posts

Posted - 2008-09-11 : 11:25:07
Hi,

I am facing problem while shifting one row into column.
My table is like this.

ID COSTSET COST
1 1 1.23
1 2 1.34
2 1 2.87
2 2 2.90

-====

I want the output like

ID COSTSET1 COSTSET2
1 1.23 1.34
2 2.87 2.90


any help will be appriciate.


Thanks
RK

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-09-11 : 18:34:36
[code]
Select ID, [1] as CostSet1, [2] as CostSet2
from
(
Select 1 as ID, 1 as CostSet, 1.23 as Cost Union All
select 1, 2, 1.34 Union All
select 2, 1, 2.87 Union All
select 2, 2, 2.90
) a
Pivot
(
Sum(Cost)
for CostSet in ([1],[2])
) p
[/code]


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page
   

- Advertisement -