I have a table of products and a table of price bands.e.g. 1 = $3, 2-4 = $2, 5+ = $1A price band row has a lowerBound, price and product ID.I need to select the correct price band for a set of products each of which have a quantity - which come from a shopping cart.SELECT p.productID, p.prodname, pb.lowerBound, pb.price, c.quantityFROM ShoppingCart cINNER JOIN products p ON p.productID = c.productID AND p.priceStyle = 2INNER JOIN productpricebands pb on pb.productID= p.productID and c.quantity >= pb.lowerboundWHERE cartID = Cast(21 As varchar(50))
This code selects all the products from a given shopping cart which are priced using price bands. It filters out all of the price bands which are too high but it doesn't get rid of the price bands which are too low.This is a sample result set...id name lowerbound price quantity11 product1 1 2.0000 8 11 product1 2 3.0000 8 11 product1 6 4.0000 8 12 product2 1 2.0000 1
You can see that the lowerbounds of the price bands are all lower than the quantity of the product as specified by the query but how do I get rid of the 2 price bands for 'product1' which shouldn'tbe there.Cheers,X-Factor