Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    29

    Question Unanswered: Stored Procedure : Returning two Variables to the Calling Procedure [SOLVED]

    Hi forum,

    I am currently learning to write TSQL and stored procedures.

    However, I have a question. I have a query that will be re-run in multiple usp.

    I want to return two index values [viz: AccessID,GroupID] to the calling procedure, and assign them to two variables in the calling procedure [viz: @AccessID, @GroupID].

    Is this possible? If so, what is the syntax required.
    Last edited by Wedgetail; 04-10-10 at 17:25.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    IF OBJECT_ID('201004101000', 'P') IS NOT NULL DROP PROCEDURE [201004101000]
    GO
    CREATE PROCEDURE [201004101000]
       @p1		INT		OUTPUT
    ,  @p2		INT		OUTPUT
    AS
    
    SET @p1 = @p1 + @p2
    SET @p2 = 0
    
    RETURN
    GO
    
    DECLARE
       @i1			INT
    ,  @i2			INT
    
    SET @i1 = 100
    SET @i2 = 5
    SELECT @i1, @i2, 'Initial'
    
    EXECUTE [201004101000] @i1, @i2
    SELECT @i1, @i2, 'Hey, what gives ???'
    
    EXECUTE [201004101000] @i1 OUTPUT, @i2 OUTPUT
    SELECT @i1, @i2, 'Ah, that''s better!'
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Feb 2009
    Posts
    29
    Thanks Pat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •