Declare @date datetime='2011-07-30' Declare @period int=12
;with cte as(
select 1 nos,@date Date
union all
select nos+1
,case when Day(@date)=31 then DATEADD(M,DATEDIFF(M,0,date)+2,0)-1
when Day(@date)=30 and DAY(DATEADD(M,1,date)-DAY(DATEADD(M,1,date)))in(29,28)
then (DATEADD(M,DATEDIFF(M,0,date)+2,0)-2)
when Day(@date)=29 and DAY(DATEADD(M,1,date)-DAY(DATEADD(M,1,date)))=28
then (DATEADD(M,DATEDIFF(M,0,date)+2,0)-3)
else DATEADD(M,1,date) end
from cte where nos+1<=@period
)select * from cte