How to query on table returned by Stored procedure within a procedure

后端 未结 3 1447
野性不改
野性不改 2020-12-22 07:45

I have a stored procedure that is performing some ddl dml operations. It retrieves a data after processing data from CTE and cross apply and other such complex things.

3条回答
  •  攒了一身酷
    2020-12-22 08:20

    This is not possible.

    The only way I can think of is to insert the results from the Stored Proc in to a temp table and query the temp table. This won't work in your scenario as you are returning 4 tables.

    Could you not rewrite the query you are interested in as a function or view?

    EDIT:

    You would do something along the lines of this (only if the Stored Proc returns one table)

    Create Proc dbo.usp_FetchUsers
    
    as
    
    begin
    
    Select UserId, UserName
    From Users
    
    End
    Go
    
    Create Table #t
    (
    UserId int,
    UserName varchar(50)
    )
    
    Insert Into #t
    Exec dbo.usp_FetchUsers
    
    Select * From #t
    Where UserId = 4
    
    drop table #t
    

提交回复
热议问题