If you say so....USE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99(DiscountOption_ID int, Discount_ID int, QTY int, Discount_Percentage int)GOINSERT INTO myTable99(DiscountOption_ID, Discount_ID, QTY, Discount_Percentage)SELECT 1, 1, 1, 0 UNION ALLSELECT 2, 1, 3, 10 UNION ALLSELECT 3, 1, 5, 15 UNION ALLSELECT 4, 1, 10, 20GODECLARE @Order IntSELECT @Order = 8 SELECT * FROM ( SELECT Discount_ID, MAX(QTY) AS MAX_QTY FROM myTable99 WHERE QTY < @Order GROUP BY Discount_ID ) AS x JOIN myTable99 y ON x.Discount_Id = y.Discount_Id AND x.MAX_QTY = y.QTYGOSET NOCOUNT OFFDROP TABLE myTable99GO
I'm sure there's a better solution....Brett8-)