MS SQL: Suppress return value of stored procedure called in stored procedure

后端 未结 3 533
一个人的身影
一个人的身影 2021-01-11 13:34

I think I have the same problem as kcrumley describes in the question \"Problem calling stored procedure from another stored procedure via classic ASP\". However his questio

3条回答
  •  無奈伤痛
    2021-01-11 14:17

    Its not the NOCOUNT thats causing this, your stored procedures have a select each so each one is coming in its own result set. This could be avoided by changing your first stored procedure to use output parameters to pass the number 1 back rather than doing a select. The second stored procedure could then examine the output parameter to get the data it needs to run.

    Try something like this

    CREATE PROCEDURE Proc1
    (
        @RetVal INT OUTPUT
    )
    AS
    SET NOCOUNT ON
    SET @RetVal = 1
    


    CREATE PROCEDURE Proc2
    AS
    SET NOCOUNT ON
    DECLARE @RetVal int
    EXEC    [dbo].[Proc1]
            @RetVal = @RetVal OUTPUT
    SELECT  @RetVal as N'@RetVal'
    

提交回复
热议问题