我有以下递归 CTE,它在 SQL 的 OpenQuery 函数中使用。我使用 OpenQuery 来查询 SQL 链接服务器。
(不工作)
SELECT * FROM OPENQUERY([MyLinkedServerDB], 'WITH SPChainCTE (NAME, INHERIT_FROM)
AS
(
Select sp.NAME, sp.INHERIT_FROM from PRODUCT AS sp
where NAME = ''ProductName''
UNION ALL
Select sp.NAME, sp.INHERIT_FROM from PRODUCT AS sp
INNER JOIN SPChainCTE AS ch on sp.NAME = ch.INHERIT_FROM
)
Select NAME, INHERIT_FROM from SPChainCTE;
');
上述 CTE 不起作用。
但是,如果我使用 OpenQuery 执行非递归 CTE,它就可以正常工作。(这有效)
SELECT * FROM OPENQUERY([FP], 'WITH SPChainCTE (NAME, INHERIT_FROM)
AS
(
Select sp.NAME, sp.INHERIT_FROM from ENG.FOCALPOINT.SW_PRODUCT AS sp
where sp.NAME = ''ProductName''
)
Select NAME, INHERIT_FROM from SPChainCTE;
');
有什么建议么?我在这里错过了什么吗?