gpt4 book ai didi

sql - 最大递归 100 在语句完成之前已用完

转载 作者:行者123 更新时间:2023-12-04 12:59:45 25 4
gpt4 key购买 nike

我不断收到 max recursion error 有了这个查询。

起初我认为这是因为返回了一个空值,然后它会尝试匹配导致错误的空值,但是,我重写了我的查询,因此不返回空值并且错误仍然发生。

重写此函数的最佳方法是什么,以免发生错误

WITH EmployeeTree AS
(
SELECT
EMP_SRC_ID_NR Id, USR_ACV_DIR_ID_TE Uuid,
CASE Employees.APV_MGR_EMP_ID
WHEN Null THEN '0'
ELSE Employees.APV_MGR_EMP_ID
END as ApprovalManagerId
FROM
dbo.[tEmployees] as Employees WITH (NOLOCK)
WHERE
APV_MGR_EMP_ID = @Id
and Employees.APV_MGR_EMP_ID is not null
and Employees.EMP_SRC_ID_NR is not null

UNION ALL

SELECT
EMP_SRC_ID_NR Id, USR_ACV_DIR_ID_TE Uuid,
CASE Employees.UPS_ACP_EMP_NR
WHEN Null THEN '1'
ELSE Employees.UPS_ACP_EMP_NR
END as ApprovalManagerId
FROM
dbo.[tEmployees] as Employees WITH (NOLOCK)
WHERE
UPS_ACP_EMP_NR = @Id
and Employees.APV_MGR_EMP_ID is not null
and Employees.EMP_SRC_ID_NR is not null

UNION ALL

SELECT
Employees.EMP_SRC_ID_NR, Employees.USR_ACV_DIR_ID_TE,
CASE Employees.APV_MGR_EMP_ID
WHEN Null THEN '2'
ELSE Employees.APV_MGR_EMP_ID
END
FROM
dbo.[tEmployees] as Employees WITH (NOLOCK)
JOIN
EmployeeTree ON Employees.APV_MGR_EMP_ID = EmployeeTree.Id
where
Employees.APV_MGR_EMP_ID is not null
and Employees.EMP_SRC_ID_NR is not null
)
SELECT
Id AS [EmployeeId],
Uuid AS [EmployeeUuid],
ApprovalManagerId AS [ManagerId]
FROM EmployeeTree

最佳答案

指定 maxrecursion option在查询结束时:

...
from EmployeeTree
option (maxrecursion 0)

这允许您指定 CTE 在生成错误之前可以递归的频率。 Maxrecursion 0 允许无限递归。

关于sql - 最大递归 100 在语句完成之前已用完,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9650045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com