Results 1 to 7 of 7

Thread: Stored procedure result to variable

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Stored procedure result to variable

    How would I assign the value of the result of executing a stored procedure to a variable.

    I tried this:
    Code:
    exec @var = proc1
    But this assigns the return value and not the result , to @var.

    I believe the return value will return 0 if no errors occur.
    Thanks

  2. #2
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: Stored procedure result to variable

    I have not tried it but maybe you could do
    Code:
    set @var = exec proc1
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: Stored procedure result to variable

    No it didnt work,..

    I tried this in the end it did work, I know I could also use output parameters.

    Code:
    DROP TABLE #temp_table
    CREATE TABLE #temp_table (availability int)
    INSERT INTO #temp_table exec SelectALLTest
    SELECT availability FROM #temp_table

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: Stored procedure result to variable

    Got the feeling there must be a better way,.... without using OUTPUT parameters,..

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Stored procedure result to variable

    It would depend on the stored procedure.

    What are it's results? A single value, a resultset?
    If the result is a single integer value just set the Return value of the sproc. It will then be loaded into your @var variable.

    What have you got against OUTPUT parameters.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: Stored procedure result to variable

    Hi, it´s a resultset.
    I do not have anything against output parameters,but wouldn´t like to modify an existing sp.

  7. #7
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Stored procedure result to variable

    if it's result set than Inline Table-Values function will be the best option for you, by this way you can directly worked upon the result set retun by function without creating Temp Table.
    __________________
    Rate the posts that helped you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width