开发者

Call a Stored procedure in SQL CTE

Are you allowed to exec stored procedures within a SQL CTE statement? I'm a bit new to sql c开发者_如何学编程te queries...


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜