MAX doesn't work. See this code:SET NOCOUNT ONCREATE TABLE Price(Vendor INT,ItemNo INT,Price INT,MinQty INT)CREATE TABLE TRX(Vendor INT,ItemNo INT,Quantity INT)INSERT INTO Price VALUES(1,122, 100, 500)INSERT INTO Price VALUES(1,122, 200, 200)INSERT INTO Price VALUES(1,122, 300, 100)INSERT INTO Price VALUES(1,122, 450, 50)INSERT INTO Price VALUES(1,122, 600, 1)INSERT INTO TRX VALUES(1, 122, 152)SELECT MIN(p.Price)FROM Price p INNER JOIN TRX t ON p.Vendor = t.Vendor AND p.ItemNo = t.ItemNoWHERE p.MinQty < t.QuantityDROP TABLE PriceDROP TABLE TRX
If I used MAX, I would get $600 instead of $300.My version is slightly better than yours. If you take a look at the execution plan for both in one window, you'll notice mine uses 48.32$ of the batch and yours uses 51.68%.I prefer the JOIN syntax as it is SQL-92 syntax.Tara