sql with 递归 查询特定区间日期

 

 

 

declare @startDay smalldatetime ='2013-01-01'  
;with cte as(
    select @startDay as d
    union all
    select DATEADD(d,1,d) as d
    from cte
    where d<'2019-05-01'
)  
select * from  cte

--设置循环次数,0为无限制
OPTION(MAXRECURSION 0)

你可能感兴趣的:(with)