I have a table of items that have a origin date and a life span. I want to create a procedure that selects all of the items that will need to be replaced in a specific duration. I feel like there is a math way of doing this in the where clause of a single select. The only way i can think of doing it is iterating though the years and appending the items that would be up for replacement... that seems super slow and inefficient. How should I approach this issue?
Details per comment requests:
Database Engine: SQL Server 2005
Source Table:
CREATE TABLE Items
(
ID int,
ItemName varchar(255),
InstallYear int,
UsefullLife int
);
Desired stored procedure format:
GetReplacementsWithinYearRange(startyear int, endyear int)
Desired output:
ItemID - ItemName - ReplaceYear
More details:
Sample Records:
1 item1 2010 5
2 item2 2011 6
Desired results for range between 2010 and 2030:
1 item1 2010
1 item1 2015
1 item1 2020
1 item1 2025
1 item1 2030
2 item2 2011
2 item2 2017
2 item2 2023
2 item2 2029