TSQL: Call a stored procedure from another stored procedure and read the result

后端 未结 5 1641
自闭症患者
自闭症患者 2020-12-14 15:29

I have a stored procedure that, ending with a SELECT, returns a recordset. I can call it within anoher stored procedure like this:

EXEC procedure @param
         


        
5条回答
  •  攒了一身酷
    2020-12-14 16:03

    AFAIK, you can't. What you probably want to do is use a function for your first (or both) procedures. Functions can only return one thing, but they can return a table. Stored procedures can return multiple results, but not to other functions/stored procedures.

    e.g.:

    CREATE FUNCTION [dbo].[fn_GetSubordinates] (
        @sPersonID VARCHAR(10),
        @nLevels INT
    )
    RETURNS @tblSubordinates TABLE
    (
        Person_Id VARCHAR(10),
        Surname char(25),
        Firstname char(25)
    )
    AS
    BEGIN
        ...
    

提交回复
热议问题