I have a function that takes any date and translates it to another date within a different year (the point of it is to preserve the weekday, week number and month, but thats not really relevant). I use it to translate a list of dates and create a temporary table that maps the original date to the mapped date using the function. The query looks like this:
Select InputDates.Date as InputDate, dbo.GetFutureDate(InputDates.Date,2012) as PastDate
INTO #DateMap
FROM InputDates
InputDates is the list of dates that I need to translate. dbo.GetFutureDate is the translation function.
As you can see the year is hardcoded, which is what I am trying to change. I have a list of years in another table. I want to create a dynamic sql statement with a series of SELECT statements like the one above, changing the year based on the list of years I have and then combine them together using Union All.
What's the best way for me to do this?