SQL Server 2000
I have a table which lists out the months where a particular product can be sold.
ProductCode MonthNum MonthName
XXX 1 January
XXX 2 February
YYY 1 January
YYY 3 March
YYY 5 May
ZZZ 6 June
ZZZ 7 July
I need to construct a query that would allow me to pass some parameters:
ProductCode
LatestMonthNum
LatestYear
FutureForecast
that would allow me to construct a set of data list with the total rows based on the number of FutureForecast value and the rows’ value would be beyond the passed LatestMonthNum and LatestYear parameter values.
For example, if I pass the following values to the query:
ProductCode YYY
LatestMonthNum 5
LatestYear 2012
FutureForecast 5
I would have the data as follows:
ProductCode MonthNum Year
YYY 1 2013
YYY 3 2013
YYY 5 2013
YYY 1 2014
YYY 3 2014
I would create a table of months and years in the future (something like a numbers table):
Then you can join your products table with the future!