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
 Please help make pivot query

Author  Topic 

JasonAnt
Starting Member

23 Posts

Posted - 2007-09-26 : 12:58:11

I have tbWarehouseStock, contain
WHCode Item Stock
------ ------ -----
WH001 Pencil 10
WH001 Pen 10
WH002 Pencil 5
WH003 ruler 100

How to make pivot query like this, I am thinking of dynamic SQL but dont know how to do this

Item WH001 WH002 WH003 WH004 WH005 ....
------ ----- ----- ----- ----- -----
Pencil 10 5 0
Pen 10 0 0
Ruler 0 0 100

thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-26 : 12:59:36
How many distinct WHCodes are there?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

JasonAnt
Starting Member

23 Posts

Posted - 2007-09-26 : 13:00:58
assume max 100 warehouses
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-26 : 13:05:31
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=crosstab,pivot


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -