I have a computed column in MS SQL 2005 that does some VAT calculations. The website uses invoices that can only be generated once and rely on the value in the computed column to work out the VAT.
Unfortunately, a bug was found that means that the the VAT value calculated was off by a few cents. Not a huge problem but we can’t change the values from all the previously computed values as these need to be honoured on the invoices.
tldr;
How do I change the calculation for a computed column without re-calculating the values that have already be calculated?
Long story short, you can’t, because the computed column definition applies to all rows in the table. But why are you using a computed column here anyway? If (when) the VAT rate changes, the rules for applying it to goods and services change, and the number of invoices increases over time, then a computed column becomes more and more awkward as a solution.
It would be a lot simpler and safer to calculate the VAT once, store it in a column and then just don’t update the value. You can use permissions, triggers and/or auditing to ensure that the value is not changed after being entered.
So I would add a new, non-computed column, copy the values from the computed column and drop the computed column (see this question). Plus whatever application development you need to do to actually calculate the values in the first place, of course. It’s some extra work but since you’ve found a bug you have to fix it anyway.