Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Update Dynamic Period End Date

1 view
Skip to first unread message

SQL Servant

unread,
Jul 20, 2010, 9:00:29 AM7/20/10
to
I have a table similar to this sample:

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

0 new messages