Call a Stored procedure in SQL CTE

前端 未结 2 1807
温柔的废话
温柔的废话 2020-12-10 10:33

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

相关标签:
2条回答
  • 2020-12-10 10:50

    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 讨论(0)
  • 2020-12-10 11:06

    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
    
    0 讨论(0)
提交回复
热议问题