how can pass the output values of one procedure to other procedure

  • Hi

    all

    how can pass one sp(stored procedure) output values to other sp input values

     

  • Declare @MyParam as int

    set @MyParam = 6

    EXEC dbo.MySP1 @MyParam output

    --let's say that MySP1 set the param to 8

    EXEC dbo.MySP2 @MyParam

  • If it would make sense in your context, you could call one stored procedure from another.

    Thus Procedure A calls Procedure B and then uses the output from Procedure B to do its work. 

     

    Within procedureA

    Decalare @param as [datatype]

    exec dbo.ProcedureB @param output

    [do the work of ProcedureA using the value of @param]

  • Create Procedure TestB (@Parameter1 Varchar(10),@Parameter2 Varchar(10) Output) as

     Select 'Inside TestB @Parameter1 : ',@Parameter1,'@Parameter2 : ',@Parameter2

     Select @Parameter2='1'

    Return

    go

    Create Procedure TestA (@Parameter1 Varchar(10)) as

     Declare @Parameter2 Varchar(10)

     Select @Parameter2='1',@Parameter1='0'

     Select 'TestA Before @Parameter2 : ',@Parameter2

     Exec TestB @Parameter1,@Parameter2 Output

     Select 'TestA After @Parameter2 : ',@Parameter2

    Return

    go

    Exec TestA 'A'

    Go

    Drop procedure TestA

    Drop Procedure TestB

    Go

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply