Sql server cte上的TSQL Maxrecursion
我得到这个错误: 语句之前已用尽最大递归100 完成 运行此函数时:Sql server cte上的TSQL Maxrecursion,sql-server,tsql,stored-procedures,sql-server-2012,sql-server-2012-express,Sql Server,Tsql,Stored Procedures,Sql Server 2012,Sql Server 2012 Express,我得到这个错误: 语句之前已用尽最大递归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
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
但我在选项单词前面有一个错误156。
你知道为什么吗?你可能把选项放错地方了。它需要在哪里之后
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
你到底在哪里附加了这个选项MAXRECURSION 200???您能告诉我们您对这个选项的查询吗?第二个选项有效,但我必须将dbo.isfestitalodate更改为dbo.isfestitalodateddd,number,@dateearly!第二种方法是危险的,因为spt_重视未记录的Microsoft内容,这些内容有一天可能会被弃用和删除。。。
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