M
Mike Thomas
This is more of a strategy question - we are going to begin to price goods
based on the quanity break from suppliers.
There is a part table with the partkey, part #, supplier key, MOQ etc.
There is also a part_cost table with
pcKey
partkey
lower_quantity
price
I am trying to figure out a graceful way to run an SQL query which will
extract a price based on order qunatity. One option would be:
SELECT price FROM part_cost WHERE partkey = lng_MyPartKey
then loop thru the recordset testing lower_quantity until the right one is
found. This is a very bad fit with existing queries and reports where only
one record is needed.
Another possibility would be to add a field to the part_cost table suach as
'upper_quantity', then do:
SELECT price FROM part_cost WHERE partkey = lng_MyPartKey AND
lng_MyQuantity >= part_cost.lower_quantity AND lng_MyQuantity <=
part_cost.upper_quantity
but this seems combersome, and I have to figure out a way to deal with
upper_quantity when it is in the record with the last break, eg any quantity
over, for example, 200 gets price X (or a situation where there is no
quantity break, eg any order >= 1 gets the same price.) I want to avoid
setting the last upper bound to some very high number, say one million, to
hopefully cover all situations.
This must be a common scenario. Is there a more clean way to deal with it?
Many thanks
Mike Thomas
based on the quanity break from suppliers.
There is a part table with the partkey, part #, supplier key, MOQ etc.
There is also a part_cost table with
pcKey
partkey
lower_quantity
price
I am trying to figure out a graceful way to run an SQL query which will
extract a price based on order qunatity. One option would be:
SELECT price FROM part_cost WHERE partkey = lng_MyPartKey
then loop thru the recordset testing lower_quantity until the right one is
found. This is a very bad fit with existing queries and reports where only
one record is needed.
Another possibility would be to add a field to the part_cost table suach as
'upper_quantity', then do:
SELECT price FROM part_cost WHERE partkey = lng_MyPartKey AND
lng_MyQuantity >= part_cost.lower_quantity AND lng_MyQuantity <=
part_cost.upper_quantity
but this seems combersome, and I have to figure out a way to deal with
upper_quantity when it is in the record with the last break, eg any quantity
over, for example, 200 gets price X (or a situation where there is no
quantity break, eg any order >= 1 gets the same price.) I want to avoid
setting the last upper bound to some very high number, say one million, to
hopefully cover all situations.
This must be a common scenario. Is there a more clean way to deal with it?
Many thanks
Mike Thomas