Product / Factory / DateFrom / DateTo / Cost
A / London / 2009-06-05 / 2049-12-31 / 15.50
A / Beijing / 2009-06-05 / 2010-07-09 / 1.20
A / Beijing / 2010-07-10 / 2049-12-31 / 1.25
The DateTo column is currently all NULL. The table is updated daily and I
need to update the DateTo field so that:
1. If a product has a new cost (e.g. last row) then the previous cost row
(row 2 here) will have DateTo value that is one day (or even one minute)
before the new DateFrom value (in row 3).
2. All latest cost rows (1 and 3 here) have some future date.
This way I will have clear period start and end dates and will be able to
join this table to the transactions table, which has dates and not date
ranges (... ON t.date BETWEEN c.DateFrom AND c.DateTo).
I hope I have explained my problem ok.
Any advice much appreciated.
SQL Servant