locked
uses of the result of one procedure in another procedure RRS feed

  • Question

  • i want to use the result of one procedure(A) in other procedure(B) .

    So how can i use this logic????

    another thing in A i m executing this procedure by some input parameter.So i want that in B while caling A,the execute query of A should take the input parameter from the curser used in B.

    please anyone tell me the solution.....

    Advancely thanks.........

    Wednesday, August 17, 2011 3:08 PM

Answers

  • Wrong forum, but I can't move the posts!  Very crude example which just provides the squared value of your input to ProcB.  ProcB calls ProcA which outputs the square value.

    CREATE PROCEDURE ProcA (@InputVal SMALLINT, @OutputVal SMALLINT OUTPUT)
    AS
    BEGIN
    	SELECT @OutputVal = (@InputVal * @InputVal)
    END
    GO
    CREATE PROCEDURE ProcB (@Multiplier SMALLINT)
    AS
    BEGIN
    	DECLARE @Val INT
    
    	EXEC ProcA @InputVal = @Multiplier, @OutputVal = @Val OUTPUT
    
    	SELECT @Val
    END
    GO
    
    EXEC ProcB @Multiplier = 9 -- Returns 81
    
    DROP PROCEDURE ProcB
    DROP PROCEDURE ProcA
    
    


     


    Clive
    www.sqlsvrdba.com
    Thursday, August 18, 2011 11:07 AM

All replies

  • Wrong forum, but I can't move the posts!  Very crude example which just provides the squared value of your input to ProcB.  ProcB calls ProcA which outputs the square value.

    CREATE PROCEDURE ProcA (@InputVal SMALLINT, @OutputVal SMALLINT OUTPUT)
    AS
    BEGIN
    	SELECT @OutputVal = (@InputVal * @InputVal)
    END
    GO
    CREATE PROCEDURE ProcB (@Multiplier SMALLINT)
    AS
    BEGIN
    	DECLARE @Val INT
    
    	EXEC ProcA @InputVal = @Multiplier, @OutputVal = @Val OUTPUT
    
    	SELECT @Val
    END
    GO
    
    EXEC ProcB @Multiplier = 9 -- Returns 81
    
    DROP PROCEDURE ProcB
    DROP PROCEDURE ProcA
    
    


     


    Clive
    www.sqlsvrdba.com
    Thursday, August 18, 2011 11:07 AM
  • Clives situation looks pretty good, if you want to share parameters across stored procedures, this should be the soution. If you want to share data between the procedures, have a look at the following article from Erland:

    http://www.sommarskog.se/share_data.html

    -Jens


    Jens K. Suessmeyer http://blogs.msdn.com/Jenss
    Friday, August 19, 2011 11:10 AM
  • If you are in 2008 onwards, you can pass table parameter to a procedure, so if you get the result of the first procedure within a table variable, for istance, you can have it passed to the second one.

    Regards,

               Marco

    Sunday, August 28, 2011 9:31 AM