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 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-04 : 08:37:23
|
| Hi all.. I have a stored procedure set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[products_BLprice2] @usname varchar(100)asbegin SELECT MobID, MAX(CASE WHEN low = 1 THEN Merchant ELSE NULL END) AS LowPriceMerchant,MAX(CASE WHEN low = 1 THEN Price ELSE NULL END) AS LowPrice,MAX(CASE WHEN high = 1 THEN Merchant ELSE NULL END) AS HighPriceMerchant,MAX(CASE WHEN high = 1 THEN Price ELSE NULL END) AS HighPrice,MAX(CASE WHEN My = 1 THEN Price ELSE NULL END)-MAX(CASE WHEN low = 1 THEN Price ELSE NULL END) AS BasepriceGap,MAX(CASE WHEN My = 1 THEN Price ELSE NULL END) AS Myprice,MAX(CASE WHEN My = 1 THEN Price ELSE NULL END) AS Baseprice,MAX(CASE WHEN My = 1 THEN mobid ELSE NULL END) AS ID,MAX(CASE WHEN My = 1 THEN Bottomline_Price ELSE NULL END) AS MyBottprice,MAX(CASE WHEN My = 1 THEN Bottomline_Price ELSE NULL END) - MAX(CASE WHEN low = 1 THEN Bottomline_Price ELSE NULL END) AS BotPriceGapINTO ##TempFROM ( SELECT MobID, Merchant, Price, Bottomline_Price, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Bottomline_Price DESC) AS high, ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Bottomline_Price) AS low, CASE Merchant WHEN @usname THEN 1 ELSE 0 END AS My FROM tbl_master_Merchant ) AS tGROUP BY MobIDHAVING MAX(My) = 1 SELECT DISTINCT m.ID,t1.MPN_SKU as ProductMPN, t1.Product_Name as Description, m.Myprice,-- m.Baseprice,-- m.BasepriceGap, m.MyBottprice, m.BotPriceGap, m.LowPrice, m.LowPriceMerchant as LowMerchant, m.HighPrice, m.HighPriceMerchant as HighMerchant FROM ##Temp AS mINNER JOIN tbl_master_Product AS t1 ON t1.MobID = m.MobIDdrop table ##tempendand it generates the following outputID|PRODUCT_MPN|Description|Myprice|MyBottprice|BotPriceGap|LowPrice|LowMerchant|HighPrice|HighMerchantThe above output produced based on the column bottom_linepriceI need lowprice,highprice calculate from price column based on the column value the gap must be found out.. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-04 : 09:30:29
|
| sorry cant make out what you're asking for from query. please post some sample data from tables and explain what you want------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|