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 |
|
madtown_nihs
Starting Member
7 Posts |
Posted - 2010-03-16 : 12:07:13
|
| I have the following query. It currently returns 4 values, min/max sale, min/max price. Right now, it just straight pick min and maxs through the values. I, however, need it to consider sale = 0 if price = sale. so if a sale = price, i need the min max function to consider it 0 and min max accordingly.Thanks So MuchLudwig SELECT MIN(c.Sale) MinPrice, MAX(c.Sale) MaxPriceMIN(c.Sale_Special) MinSale, MAX(c.Sale_Special) MaxSale FROM Product a " &_LEFT JOIN Accessory_Map b " &_ON a.Product_ID = b.Product_ID " &_AND b.Accessory_Group_ID IN (3, 4) " &_LEFT JOIN Price c " &_ON b.Accessory_ID = c.Product_ID " &_LEFT join product d on d.Product_ID = b.Accessory_ID "WHERE a.Product_ID = " & rsProd("Product_ID") & " " &_AND d.Orderable = 0 AND d.Deleted = 0 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-16 : 12:10:32
|
| [code]SELECT MIN(c.Sale) MinPrice, MAX(c.Sale) MaxPriceCOALESCE(NULLIF(MIN(c.Sale_Special),MIN(c.Sale)),0) MinSale, COALESCE(NULLIF(MAX(c.Sale_Special),MAX(c.Sale)),0) MaxSale FROM Product a " &_LEFT JOIN Accessory_Map b " &_ON a.Product_ID = b.Product_ID " &_AND b.Accessory_Group_ID IN (3, 4) " &_LEFT JOIN Price c " &_ON b.Accessory_ID = c.Product_ID " &_LEFT join product d on d.Product_ID = b.Accessory_ID "WHERE a.Product_ID = " & rsProd("Product_ID") & " " &_AND d.Orderable = 0 AND d.Deleted = 0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madtown_nihs
Starting Member
7 Posts |
Posted - 2010-03-16 : 12:26:19
|
| Doesn't this just select MIN(c.Sale_Special) first if it's not null? same for max. Lets say there is this data setSale Sale Special10 840 40 90 0sale 10 - 90SS 0 - 8because at 40 s = ss, I consider it 0Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-16 : 12:29:51
|
| [code]SELECT MIN(c.Sale) MinPrice, MAX(c.Sale) MaxPriceMIN(CASE WHEN c.Sale_Special = c.Sale THEN 0 ELSE c.Sale_Special END) MinSale, MAX(CASE WHEN c.Sale_Special = c.Sale THEN 0 ELSE c.Sale_Special END) MaxSale FROM Product a " &_LEFT JOIN Accessory_Map b " &_ON a.Product_ID = b.Product_ID " &_AND b.Accessory_Group_ID IN (3, 4) " &_LEFT JOIN Price c " &_ON b.Accessory_ID = c.Product_ID " &_LEFT join product d on d.Product_ID = b.Accessory_ID "WHERE a.Product_ID = " & rsProd("Product_ID") & " " &_AND d.Orderable = 0 AND d.Deleted = 0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|