Du placerar förmodligen alternativet på fel ställe. Det måste vara efter var
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);
Men prova detta istället. Det kommer att gå snabbare...
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