spikepl
Eledittingent Beliped
- Local time
- Today, 23:26
- Joined
- Nov 3, 2010
- Messages
- 6,142
Time and time again I deal with ranges. For example, shipping, where shipping cost is determined by weight.
What would be the generally best way of storing such ranges?
Now I have different options for storing this data
I can give the upper limit of each range and the price for that range, like in tblRates1.
Con: This requires searching for the appropriate limit when I want to find the cost for a given shipment.
Pro: Simple to change, no redundant data
I can also give ranges, like in tblRates2.
Con: Redundancy, since we know that a range begins where previous range ends. But so what?
Pro: SImple in use, since I can join on non equi joins and get the right cost directly without subqueries
When managing documents, there is a similar but not exactly alike situation:
Again, one could store the data with just one of the validity-range limits, or with both limits. The latter method entails updating two records when a new revision is issued: the one for the new revision and the last one, to set the end of validity for that previous revision.
Comments?
What would be the generally best way of storing such ranges?
Code:
WeightRange Cost
0-1 1
1-5 3
5-10 10
>10 20
I can give the upper limit of each range and the price for that range, like in tblRates1.
Con: This requires searching for the appropriate limit when I want to find the cost for a given shipment.
Pro: Simple to change, no redundant data
Code:
tblRates1
----------
RateID Weight Cost
1 1 1
2 5 3
3 10 10
4 9999 20
Con: Redundancy, since we know that a range begins where previous range ends. But so what?
Pro: SImple in use, since I can join on non equi joins and get the right cost directly without subqueries
Code:
tblRates2
----------
RateID WeightLow WeightHigh Cost
1 0 1 1
2 1 5 3
3 5 10 10
4 10 9999 20
Code:
Revisions
DocID RevID ValidFrom
1 1 1/1-2013
1 2 1/1-2014
1 3 5/5-2014
Again, one could store the data with just one of the validity-range limits, or with both limits. The latter method entails updating two records when a new revision is issued: the one for the new revision and the last one, to set the end of validity for that previous revision.
Comments?
Last edited: