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
 General SQL Server Forums
 New to SQL Server Programming
 Pls help

Author  Topic 

rajukurian
Starting Member

8 Posts

Posted - 2007-02-14 : 18:14:32
i am really confused . pls help me .. i got a table in the format below.

WEEK_ID BEG_DATE SUB_TYPE TOTAL_AMOUNT
2514 11/19/2006 Gift_Certificate 1686.05
2514 11/19/2006 Order_Accommodation 1219.4
2514 11/19/2006 0:00 Order Override 124.8


but i want the output like

WEEK_ID BEG_DATE Gift_Certificate Order_Accommodation Order_Override
2514 11/19/2006 1686.05 1219.4 124.8

That means the value in sub_type should take as colums and corresponding amount should comes rows for each weekid.

Thanks..

Raju

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-14 : 20:16:52
[code]
select WEEK_ID, BEG_DATE,
Gift_Certificate = max(case when SUB_TYPE = 'Gift_Certificate' then TOTAL_AMOUNT end),
Order_Accommodation = max(case when SUB_TYPE = 'Order_Accommodation' then TOTAL_AMOUNT end),
Order_Override = max(case when SUB_TYPE = 'Order_Override' then TOTAL_AMOUNT end)
from table1
group by WEEK_ID, BEG_DATE
[/code]


KH

Go to Top of Page

rajukurian
Starting Member

8 Posts

Posted - 2007-02-15 : 08:02:43
thanks a lot khtan.
Go to Top of Page
   

- Advertisement -