Sql server 如何在不创建新数据库对象的情况下生成一系列日期?

Sql server 如何在不创建新数据库对象的情况下生成一系列日期?,sql-server,tsql,sql-server-2000,Sql Server,Tsql,Sql Server 2000,我需要创建一个查询,返回从2013年4月到现在的年份和月份,如下所示: 2013 | 4 2013 | 5 2013 | 6 2013 | 7 2013 | 8 .... | . .... | . .... | . 2015 | 1 2015 | 2 2015 | 3 2015 | 4 它必须与SQLServer2000一起工作,并且我在SE上找到的所有解决方案仅与SQLServer2005+兼容 有没有办法用这个非常古老的SGBD来实现这一点 如果没有解决方案,我会考

我需要创建一个查询,返回从2013年4月到现在的年份和月份,如下所示:

2013  | 4
2013  | 5
2013  | 6
2013  | 7
2013  | 8
....  | .
....  | .
....  | .
2015  | 1
2015  | 2
2015  | 3
2015  | 4
它必须与SQLServer2000一起工作,并且我在SE上找到的所有解决方案仅与SQLServer2005+兼容

有没有办法用这个非常古老的SGBD来实现这一点


如果没有解决方案,我会考虑创建一个数字表,但我不觉得它真的很优雅。

如果你正在使用日期,你应该总是有日历表。
declare @Startdate AS DateTime = Dateadd( year,-2,Getdate()) , 
        @EndDate DateTime = Getdate()
Declare @YearTable as Table ( CalYear int , calmonth int)

While @Startdate <= @EndDate 
BEGIN 
    Insert Into @YearTable values(YEAR(@Startdate),MONTH(@Startdate))
    set @Startdate = DateADD(Month,1,@Startdate)
END 

select * from @YearTable