0

我收到此错误:

最大递归 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。你知道为什么吗?

4

1 回答 1

7

您可能将选项放在错误的位置。它需要在 where 之后

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
于 2012-11-15T11:25:03.260 回答