我需要一个年份列表作为记录集从2004年到当前年度(以desc顺序),而不编写存储过程.这可能吗?(SQL Server 2005).所以它应该返回:
2009
2008
2007
2006
2005
2004
这使用递归CTE从2004年到现在的所有年份:
with yearlist as ( select 2004 as year union all select yl.year + 1 as year from yearlist yl where yl.year + 1 <= YEAR(GetDate()) ) select year from yearlist order by year desc;