declare @StartDate DATETIME = ‘2015/05/01’
declare @EndDate DATETIME =’2015/06/03’;
with cte as
(
select @StartDate dday
union all
select dday +1 from cte
where dday < @EndDate
)
select * from cte
option(maxrecursion 0)
本文介绍了一种使用T-SQL在SQL Server中生成指定日期范围内连续日期的方法。通过声明开始和结束日期变量,并利用CTE(公共表表达式)进行递归操作,可以有效地生成从开始日期到结束日期之间的每一天的数据。
declare @StartDate DATETIME = ‘2015/05/01’
declare @EndDate DATETIME =’2015/06/03’;
with cte as
(
select @StartDate dday
union all
select dday +1 from cte
where dday < @EndDate
)
select * from cte
option(maxrecursion 0)

被折叠的 条评论
为什么被折叠?
