Return CTE 中的存储过程结果
Return Stored Proc Results in CTE
我可以将存储过程调用到 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'.
根据评论中的对话改编的答案:
您可以使用存储过程填充 table 变量,只读权限允许您创建该变量。您也不需要使用 OpenRowSet 来填充它。只是做:
INSERT INTO @MyTableVariable
EXEC MyStoredProcedure
我自己在很多地方都这样做,我需要将存储过程结果视为 table,我可以加入或与其他 table 联合。
我可以将存储过程调用到 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'.
根据评论中的对话改编的答案:
您可以使用存储过程填充 table 变量,只读权限允许您创建该变量。您也不需要使用 OpenRowSet 来填充它。只是做:
INSERT INTO @MyTableVariable
EXEC MyStoredProcedure
我自己在很多地方都这样做,我需要将存储过程结果视为 table,我可以加入或与其他 table 联合。