Simo,
I based that on your sample of: buy 1 get 1 free buy 4 get 2 free. In both
cases that's 50% off...
Now, I would still try to do this programatically if I were you.
Here's how I'd go about it:
In your database create a table that stores two values for each product,
quantity and discount. It would look like this:
tblDiscounts
productId Quantity Discount
1 2 20%
1 3 25%
1 6 50%
2 3 25%
Then there are two different scenarious for looking up the data depending on
how you are giving out the discounts:
1) If you're only giving the discount for the exact quantity purchased look
up the discount based on productId and Quantity
SELECT Discount FROM tblDiscounts WHERE productId = 1 And Quantity = 3
2) More likely you are giving a discount for a certain number of items
purchased or greater. So you'll need to get all the discounts for the
quantity purchased and then figure out which one is the correct one. I'd use
a datareader for that:
SELECT Discount FROM tblDiscounts WHERE productId = 1 ORDER By Quantity (you
could limit this via AND Quantity >= if appropriate.)
Dim Discount As Decimal
While DataReader.Read
If DataReader.Item("Quantity") >= CustomerQuantity Then
Discount = DataReader.Item("Discount")
Else
'---The customer quantity is less than the rest of the discounts
found it's safe to exit the loop
Exit While
End While
DataReader.Close
'---Discount now has the correct discount in it.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche