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.
Author |
Topic |
ricc
Starting Member
16 Posts |
Posted - 2013-10-18 : 07:08:35
|
Hi, I have a query (SELECT * FROM Pricing) that produces the following resultsStockcode|ProductID|OurSellPrice|SupplierTypeID|CompetitorPriceSC0001___|123______|22.45_______|1_____________|25.23SC0001___|123______|21.45_______|2_____________|25.23I want to convert this to the following :Stockcode|ProductID|OurSellPriceType1|OurSellPriceType2|CompetitorPriceSC001____|123______|22.45____________|21.45____________|25.23We only have two types of suppliers but not every product is available from each type of supplier so we might get the following results:Stockcode|ProductID|OurSellPrice|SupplierTypeID|CompetitorPriceSC0002___|124______|22.45_______|1_____________|25.23Stockcode|ProductID|OurSellPriceType1|OurSellPriceType2|CompetitorPriceSC001____|123______|22.45____________|NULL_____________|25.23Does anyone have any pointers?Many thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-18 : 07:50:24
|
[code]SELECT Stockcode,ProductID,MAX(CASE WHEN SupplierTypeID = 1 THEN OurSellPrice END) AS OurSellPriceType1,MAX(CASE WHEN SupplierTypeID = 2 THEN OurSellPrice END) AS OurSellPriceType2,CompetitorPriceFROM PricingGROUP BY Stockcode,ProductID,CompetitorPrice[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|