how to pass result from a Stored Procedures

  • how can i pass the result from one Stored Procedures

    to another Stored Procedures as a '@result'

    --------

    THNKS ILAN

  • if i get you right:

    DECLARE @retval INT

    EXECUTE @retval = my_stored_proc 'x', 'y'

    PRINT @retval

    use RETURN to return any integer expression from a stored proc (exits immediately).

    if you're looking for "real" return values besides integer codes, you should use CREATE FUNCTION ...

    best regards,

    chris.

  • You can also use OUTPUT parameters for the stored procedure. This allows you to 'return' any datatype and to return more than one variable.

    
    
    CREATE PROCEDURE OutputVars
    @Output1 int OUTPUT,
    @Output2 varchar(15) OUTPUT
    AS
    SET @Output1 = 10
    SET @Output2 = 'Hello World!'
    GO

    --Call of the procedure
    DECLARE @var1 int
    DECLARE @var2 varchar(15)
    EXEC OutputVars @var1 OUTPUT, @var2 OUTPUT
    PRINT @var1
    PRINT @var2
  • I'd suggest you use the return value from a procedure in this way only to indicate the success or failure of execution. Although many developers use it this way to return integer values to the calling procedure, I prefer using OUTPUT to return non-error code.

    Joseph.

    quote:


    if i get you right:

    DECLARE @retval INT

    EXECUTE @retval = my_stored_proc 'x', 'y'

    PRINT @retval

    use RETURN to return any integer expression from a stored proc (exits immediately).

    if you're looking for "real" return values besides integer codes, you should use CREATE FUNCTION ...

    best regards,

    chris.



    Joseph

  • Its a good practice to return only error codes using return (RETURN @@ERROR). All other values to be returned should be done using OUTPUT variables.

    quote:


    I'd suggest you use the return value from a procedure in this way only to indicate the success or failure of execution. Although many developers use it this way to return integer values to the calling procedure, I prefer using OUTPUT to return non-error code.

    Joseph.

    quote:


    if i get you right:

    DECLARE @retval INT

    EXECUTE @retval = my_stored_proc 'x', 'y'

    PRINT @retval

    use RETURN to return any integer expression from a stored proc (exits immediately).

    if you're looking for "real" return values besides integer codes, you should use CREATE FUNCTION ...

    best regards,

    chris.



    Paras Shah

    Evision Technologies

    Mumbai, India


    Paras Shah
    Evision Technologies
    Mumbai, India

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

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