私max recursion error
はこのクエリでを取得し続けます。
最初はnullが返されていて、それが原因でnull値と一致してエラーが発生するためだと思っていましたが、クエリを書き直してnullが返されず、エラーが発生するようにしました。
エラーが発生しないように、この関数を書き換えるための最良の方法は何でしょうか
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
COALESCE()
。CASE Employees.APV_MGR_EMP_ID WHEN Null THEN '0' ELSE Employees.APV_MGR_EMP_ID END as ApprovalManagerId
=COALESCE(Employees.APV_MGR_EMP_ID, 0) AS ApprovalManagerID