开发者

How and where do I set the MAXRECURSION option?

开发者 https://www.devze.com 2023-01-08 23:00 出处:网络
I have a qu开发者_开发知识库ery that exhausts the default MAXRECURSION limit of 100. Giving me the following error message:

I have a qu开发者_开发知识库ery that exhausts the default MAXRECURSION limit of 100. Giving me the following error message:

The statement terminated. The maximum recursion 100 has been exhausted before statement completion.

I have found out that I need to raise the limit for this CTE using OPTION (MAXRECURSION xxx) but I don't know where to put this.

So far I've tried to put it next to where I define the CTE but it isn't working. I've also tried a few different places and it's not working either. The error I get each time is:

Incorrect syntax near the keyword 'OPTION'.

So where should I put the OPTION (MAXRECURSION XXX) command in my SQL?

with
    tab (id,start,en) AS (
                  SELECT 1, 100, 200
        UNION ALL SELECT 2, 200, 500
    ),
    cte (id,start,en) AS (
        SELECT id, start, en FROM tab
        UNION ALL
        SELECT id, start+1, en FROM cte WHERE start+1 <= en
    )
SELECT id, start
FROM cte
ORDER BY id


with tab AS 
(
    select 1 as id, 100 as start, 200 as en
    union all
    select 2, 200, 500),
    cte AS
    (
        select id,start,en from tab
        union all
        select id,start+1 , en from cte where start+1<=en
    )

SELECT id,start from cte
order by id
OPTION (MAXRECURSION 1000)
0

精彩评论

暂无评论...
验证码 换一张
取 消