sql server - How to generate a serie of date without create a new database object? -
i need create query returns years , months april 2013 following:
2013 | 4 2013 | 5 2013 | 6 2013 | 7 2013 | 8 .... | . .... | . .... | . 2015 | 1 2015 | 2 2015 | 3 2015 | 4
it must works sqlserver 2000, , solution found on se sqlserver2005+ compatible.
is there way (very) old sgbd?
if there no solution consider create table of numbers don't find elegant...
declare @startdate datetime = dateadd( year,-2,getdate()) , @enddate datetime = getdate() declare @yeartable table ( calyear int , calmonth int) while @startdate <= @enddate begin insert @yeartable values(year(@startdate),month(@startdate)) set @startdate = dateadd(month,1,@startdate) end select * @yeartable