gpt4 book ai didi

sql-server - 返回 CTE 中存储的过程结果

转载 作者:行者123 更新时间:2023-12-02 19:05:33 26 4
gpt4 key购买 nike

我可以将存储过程调用到 CTE 中吗?我有一个仅 RO 的报告数据库登录信息。我拥有 UAT 的写入权限,但想查询实时数据。

那么我可以在 CTE 中使用存储过程吗?

with clientOwes as (
exec des_Batch_GetApplicationClientOwesList
)
select a.des_applicationnumber
from des_heapplicationset a
where a.des_heapplicationid in (select applicationid from clientowes)

result was: Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'exec'.

最佳答案

根据评论中的对话改编的答案:

您可以使用存储过程来填充表变量,只读访问权限允许您创建该变量。您也不需要使用 OpenRowSet 来填充它。只要这样做:

INSERT INTO @MyTableVariable
EXEC MyStoredProcedure

我自己在很多地方都这样做,我需要将 Stored Proc 结果视为可以与其他表 JOIN 或 UNION 的表。

关于sql-server - 返回 CTE 中存储的过程结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968671/

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