declare @dt1 as datetime
declare @dt2 as datetime
set @dt1 = '2008-01-01'
set @dt2 = '2009-01-01' ;with t
as
(select @dt1 as y
union all
select dateadd(m,1,y) from t where y <@dt2)
select * from t
2024-02-14 10:52:28
declare @dt1 as datetime
declare @dt2 as datetime
set @dt1 = '2008-01-01'
set @dt2 = '2009-01-01' ;with t
as
(select @dt1 as y
union all
select dateadd(m,1,y) from t where y <@dt2)
select * from t