我收到此错误:
最大递归100在声明之前已经用尽 完成
当我运行此功能时:
WITH allDays AS (
SELECT @DateEarly AS date
UNION ALL
SELECT DATEADD(dd, 1, date) as date
FROM allDays s
WHERE DATEADD(dd, 1, date) <= @DateLate
)
SELECT *
from allDays
where dbo.isFestivo(date)>0
我尝试附加此选项:
OPTION (MAXRECURSION 200);
但是在“选项”字之前我得到一个错误156。 你知道为什么吗?
答案 0 :(得分:6)
你可能把选项放在了错误的地方。它需要在哪里
之后WITH allDays AS (
SELECT @DateEarly AS date
UNION ALL
SELECT DATEADD(dd, 1, date) as date
FROM allDays s
WHERE DATEADD(dd, 1, date) <= @DateLate
)
SELECT *
from allDays
where dbo.isFestivo(date)>0
option (maxrecursion 200);
但试试这个。它会更快......
select DATEADD(d, number, @dateearly) as [date]
from master..spt_values
where type='p'
and number<=datediff(d,@dateearly,@datelate)
and dbo.isFestivo(date)>0