我试图循环使用给定参数 From 和 To Date 的 cte。我用 cte 阅读了这个create while 循环并在我的查询中尝试了它,但结果只显示了开始日期和下一个日期。
DECLARE @fromdate datetime
DECLARE @todate datetime
SET @fromdate='2013-07-23'
SET @todate='2013-07-24'
;with dates(num) as (
select @fromdate as fromdate
union all
select @fromdate + 1
from dates
where dates.num < @todate
),
T(employee_id,actualogin,actuallogout) as (
select d.*
from dates cross apply
dbo.ufn_GET_ATTENDANCE(dates.num) d
)
SELECT * FROM T
OPTION (MAXRECURSION 0)