Author |
Topic |
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 07:17:35
|
Experts,Hello !Please bear with me for the long post ! I have a procedureset ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[sp_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 creates the following output93668 44.99 0.00 0.00 44.99 waterfilterexchange 9.96 Amazon.comThe actual table contains the following valuesmobid bottomline_price merchant price 93668 15.54 Amazon.com 9.9693668 0.00 waterfilterexchange 44.99 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 07:22:30
|
MOBID My_price Mybottomline_price botprice_gap low_price lowprice_merchant high_price highprice_merchant93668 44.99 0.00 0.00 44.99 waterfilterexchange 9.96 Amazon.com |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 07:27:35
|
My need is (If I am waterfilterexchange )MOBID My_price Mybottomline_price botprice_gap low_price lowprice_merchant high_price highprice_merchant93668 44.99 0.00 -15.54 9.96 Amazon.com 44.99 waterfilterexchange |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 07:43:04
|
Actual output generated based on the bottom_line price column the low price and high price merchant are chosen based on the bottomline_priceMy need is the low&high merchants select using price column |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 07:43:57
|
Actual output generated based on the bottom_line price column the low price and high price merchant are chosen based on the bottomline_priceMy need is the low&high merchants select using price column |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-06 : 10:16:59
|
need some help... |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-07 : 06:52:55
|
quote: My need is the low&high merchants select using price column
select max(Bottomline_Price)over(partition by merchantid)as highprice, min(Bottomline_Price)over(partition by merchantid)as lowpricefrom yourtable PBUH |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-07 : 06:59:41
|
Tnx for the response...This will select all datas generally from my table ..I need that for a particular mobid i need to find the low price and high price in a single column named price |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-07 : 07:10:34
|
In my table I have like this..For a single product I have more than two merchants.. And their details are present in my table..Bottomline_price is one column and price is another column ...Now i want to select that by passing the merchant name find the low & high price in price column and also that merchants bottom_line price...Sorry for my poor communication... |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-07 : 07:13:01
|
Juts post some sample o/p.PBUH |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-07 : 07:41:32
|
mobid...bott_price.. merchant......price93212 0.00 PCNation.com.......131.6993212...153.76...waterfilterexchange...134.9993212...154.44...ReStockIt.com...138.49 93212...149.95...RadioShack.com....149.9593212...132.99...Amazon.com.... 132.9993212...131.98...TheNerds.net...121.9993212...135.24...CostCentral.com...126.7293212...158.02...EcomSF... 145.81this is my table like this more than thousand mobid s are present.. |
 |
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2010-10-07 : 08:09:50
|
In future provide test data in a comsumable format:CREATE TABLE #Merchant( mobid int NOT NULL ,merchant varchar(35) NOT NULL ,price money NOT NULL ,bottomline_price money NOT NULL)INSERT INTO #MerchantSELECT 93668, 'Amazon.com', 9.96, 15.54UNION ALL SELECT 93668, 'waterfilterexchange', 44.99, 0.00 Also provide the result in a readable format. A select statement will do.-- With @usname = 'waterfilterexchange'SELECT 93668 AS MOBID ,44.99 AS My_price ,0.00 AS Mybottomline_price ,-15.54 AS botprice_gap ,9.96 AS low_price ,'Amazon.com' AS lowprice_merchant ,44.99 AS high_price ,'waterfilterexchange' AS highprice_merchant You also state:"Actual output generated based on the bottom_line price column the low price and high price merchant are chosen based on the bottomline_priceMy need is the low&high merchants select using price column"Given the above the obvious answer is to change the ORDER BY part of your ROW_NUMBER() functions from Bottomline_Price to Price.This seems to work:DECLARE @usname varchar(35)SET @usname = 'waterfilterexchange'SELECT MobID ,MAX(CASE WHEN My = 1 THEN Price END) AS Myprice ,MAX(CASE WHEN My = 1 THEN Bottomline_Price END) AS MyBottprice ,MAX(CASE WHEN My = 1 THEN Bottomline_Price END) - MAX(CASE WHEN low = 1 THEN Bottomline_Price END) AS BotPriceGap ,MAX(CASE WHEN low = 1 THEN Price END) AS LowPrice ,MAX(CASE WHEN low = 1 THEN Merchant END) AS LowPriceMerchant ,MAX(CASE WHEN high = 1 THEN Price END) AS HighPrice ,MAX(CASE WHEN high = 1 THEN Merchant END) AS HighPriceMerchantFROM( SELECT MobID, Merchant, Price, Bottomline_Price ,ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price DESC) AS high ,ROW_NUMBER() OVER (PARTITION BY MobID ORDER BY Price) AS low ,CASE WHEN Merchant = @usname THEN 1 ELSE 0 END AS My FROM #Merchant) DGROUP BY MobIDHAVING MAX(My) = 1 Overall your posts are very difficult to read due to:1. the data being poorly formatted and not easily copied into Management Studio.2. extra information confusing the issue. What have #temp and tbl_master_Product got to do with the problem?People are more likely to answer your posts if they can easily read and test them.PS. I have just noticed that you have posted more sample data.What is the point if you do not provide the corresponding results.You need to engage brain before posting! |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-10-07 : 10:01:24
|
First thanks for your advice and thanks for your kindly help.. |
 |
|
|