I'm trying to implement a decay mechanism in SQL that's based on the amount of time that has gone by. So the item "decays" faster as time goes by (based on the previous product).
This is accomplished by having a "Decay" value, a date of Generation, and a periodicity AKA the amount of time between applications of the decay value.
So if an item has a decay of 25%, starts at 1, with a date of generation of today and 3.5 minutes ago, it will already have decayed 3x resulting in a 'weighted value':
1m - 1.25
2m - 1.5625
3m - 1.953125
etc
s * ((1+d) ^ n)
where
s = starting value
d = decay % as decimal
n = number of elapsed periods
With the relevant SQL being:
ORDER BY
1.00 * POWER((1.00+[Decay]),CONVERT(float, DATEDIFF(minute,[GenerationDate],GETUTCDATE())))
However this causes arithmetic overflows, so now I have to determine something in the WHERE statement that would stop me from ordering by items that are too old and would cause an overflow, or at least maxing it out to the max value of a decimal.