How to pass parameters from outer procedure to inner procedure

  • I have 2 proc , calling one proc inside another. There are 2 parameters need to pass .When I call the main procedure and it takes parameter.There is considition if the value of the parameter I pass is less than 0 it should call other proc.But when I call the procedure with negative values it is not passing the same value to inner procedure.Whne I check the values it is passing null.How to pass parameters from main proc to inner proc.

  • We need to see some code to help you. Doesn't have to be full-blown sproc, but must cover your issues completely.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • create proc proc1

    ( @alloc_id int = null,

    @trace int = 0

    as

    If @alloc_id < 0

    exec proc 2

    Code of proc2 is

    create proc proc2

    ( @alloc_id int = null,

    @trace int = 0

    as

    Inner query for both procs are diff outer parameters remain the same

  • Why don't you pass the parameter like

    If @alloc_id < 0

    exec proc2 @alloc_id

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • savibp3 (12/9/2016)


    I have 2 proc , calling one proc inside another. There are 2 parameters need to pass .When I call the main procedure and it takes parameter.There is considition if the value of the parameter I pass is less than 0 it should call other proc.But when I call the procedure with negative values it is not passing the same value to inner procedure.Whne I check the values it is passing null.How to pass parameters from main proc to inner proc.

    Check the logic, it must of course include an action for negative values, most often this problem is due to a missing ELSE statement.

    😎

  • joeroshan (12/9/2016)


    Why don't you pass the parameter like

    If @alloc_id < 0

    exec proc2 @alloc_id

    Yep.

    An ELSE may be needed to complete the needs of the OP.

    Note that I ALWAYS urge clients to ALWAYS put BEGIN/END around IFs, even if just single line. Avoids some REALLY nasty logic flaws in the future!

    If @alloc_id < 0

    BEGIN

    EXEC proc2 @alloc_id

    END

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 6 posts - 1 through 5 (of 5 total)

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