with monthtemp(mon)
as
(
select 1 mon
union all
select mon+1 from monthtemp where mon<12
)
,yeartemp(yea)
as
(
select 1991 yea --开始年份
union all
select yea+1 from yeartemp where yea<datepart(year,getdate())
)
select cast(yea as varchar(50))+'-'+case when mon<10 then '0'+cast(mon as varchar(50)) else cast(mon as varchar(50)) end ymon,yea,mon from yeartemp,monthtemp
where (cast(yea as varchar(50))+'-'+cast(mon as varchar(50))+'-01')<=getdate()
order by yea,mon;