在 SQL CTE 中调用存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6332509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:57:16  来源:igfitidea点击:

Call a Stored procedure in SQL CTE

sqlsql-server-2005common-table-expression

提问by user167698

Are you allowed to exec stored procedures within a SQL CTE statement? I'm a bit new to sql cte queries...

是否允许在 SQL CTE 语句中执行存储过程?我对 sql cte 查询有点陌生...

回答by gbn

No, sorry. SELECTs statments only

不,对不起。仅选择语句

If you need to use stored proc output (result set), then it'd be a temp table

如果您需要使用存储过程输出(结果集),那么它就是一个临时表

CREATE TABLE #foo (bar int...)

INSERT #foo (bar, ...)
EXEC myStoredProc @param1...

-- more code using #foo

回答by Sagar Dev Timilsina

You can also use table variable :

您还可以使用表变量:

DECLARE @tbl TABLE(id int ,name varchar(500) ,...)      
    INSERT INTO @tbl        
    EXEC myprocedure @param ..

with cte as (
    SELECT * FROM @tbl  
)
select * from cte