How do I list the months for the last 10 years starting from the current month using SELECT statement?
I can list all the current months since the last 10 years but could not list all the 12 subsequent months in the years
select top 10 dateadd(year, -1*row_number() over (order by name)+1, convert (varchar, getdate(),112)) as y
from sys.objects
will give me the last 10 years from the current month
202403...201503
select top 12 dateadd(MM, -1*row_number() over (order by name)+1, convert (varchar, getdate(),112)) as m
from sys.objects
will give me the last 12 month from today
But how do I merge the 2 statements above to get all the months from the last 10 years from the current month?
Please advise.