I need to create a table (or view) that will create new rows based on an initial, and subsequent rows. I have a table fields called 'next replacement date' and ' lifecycle years'. For each record (in my case each component within a house) I need to work out when all subsequent replacement dates will occur based on the initial 'next replacement date' and the 'lifecycle years'
The initial calculation would be:
Next replacement date (from table)+ lifecycle years (from table)= Date 1
Then I would want to calculate subsequent dates like this:
Date 1 + lifecycle years = date 2 Date 2 + lifecycle years = date 3 Date 3 + lifecycle years = date 4
And so on, up to a limit of say, maximum date = 1/1/2050
I think this is what’s known as a recursive function (?) but I’m stumped as to how to do it
You can do it using recursive queries, but seems like it can also be done without recursion. If my understanding is correct, the formula would be the following, which is a straight query rather than recursive query.
Date1 = NextReplacementDate + Life cycle Years; Date2 = NextReplacementDate + Life cycle Years * 2 Date3 = NextReplacementDate + Life cycle Years * 3
DateN = NextReplacementDate + Life cycle Years * N
I'd just use a Tally Table for such a thing. If you'd post the CREATE TABLE and INSERT scripts to create an example table with some data, I could show you how easy it is.