如何以及在何处设置 MAXRECURSION 选项?

How and where do I set the MAXRECURSION option?(如何以及在何处设置 MAXRECURSION 选项?)
本文介绍了如何以及在何处设置 MAXRECURSION 选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,它耗尽了默认的 MAXRECURSION 限制 100.给我以下错误消息:

I have a query that exhausts the default MAXRECURSION limit of 100. Giving me the following error message:

语句终止.最大递归 100 在语句完成前已用完.

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

我发现我需要使用 OPTION (MAXRECURSION xxx) 来提高这个 CTE 的限制,但我不知道把它放在哪里.

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.

到目前为止,我已经尝试将它放在我定义 CTE 的位置旁边,但它不起作用.我也试过几个不同的地方,它也不起作用.我每次得到的错误是:

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:

关键字OPTION"附近的语法不正确.

Incorrect syntax near the keyword 'OPTION'.

那么我应该将 OPTION (MAXRECURSION XXX) 命令放在我的 SQL 中的什么位置?

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)

这篇关于如何以及在何处设置 MAXRECURSION 选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)