Store SP value in another variable

  • i have a SP for counterID generation and i want to use this SP in another SP and this is want to achive by storing the SP generated value in another variable.

    i m doing : declare @a varchar

    set @a=exec SPcounter

    but this is giving error.

  • I had the same question and after pouring thru posts here and on the web, found the solution in BOL (of course) under the "Returning Data by Using OUTPUT Parameters ". I wanted a string returned, here's an example:

    DECLARE @someVar varchar(max)

    EXEC usp_YourStoredProc @someVar OUTPUT

    PRINT @someVar

    For you, as it looks like you're just returning an INT, you can use the RETURN statement in your original stored procedure (again, check out BOL).

    HTH

    ----------------------------------------------------------------------------
    Sacramento SQL Server users group - http://sac.sqlpass.org
    Follow me on Twitter - @SQLDCH
    ----------------------------------------------------------------------------

    Yeah, well...The Dude abides.

Viewing 2 posts - 1 through 1 (of 1 total)

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