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)
 grouping

Author  Topic 

bjcc77
Starting Member

5 Posts

Posted - 2006-02-02 : 08:11:11
I have the following a table called stock

Code Description PriceGroup Price
560002 Panel 1 193.31
560002 Panel 2 241.63
560002 Panel, 3 277.88
560002 Panel, 4 400.86
560003 Panel 1 184.34
560003 Panel 2 235.64
560003 Panel, 3 267.99
560003 Panel, 4 412.77

and i am needing to insert this data into a new table .This is how I would like the data to appear in the a new table called Stock1

Code Description PG1 PG2 PG3 PG4
560002 Panel 193.31 241.63 277.88 400.86
560003 Panel 184.34 235.64 267.99 412.77

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-02 : 08:34:21
[code]select code, description,
sum(case when price_group = 1 then price else 0 end) as pg_1,
sum(case when price_group = 2 then price else 0 end) as pg_2,
sum(case when price_group = 3 then price else 0 end) as pg_3,
sum(case when price_group = 4 then price else 0 end) as pg_4
from stock
group by code, description[/code]

----------------------------------
'KH'


Go to Top of Page

bjcc77
Starting Member

5 Posts

Posted - 2006-02-02 : 08:38:15
Thank you
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-02 : 08:50:17
Also refer this for dynamic CrossTab
http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

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

- Advertisement -