Can't store results from EXEC into variable

  • Trying to store the results from a stored procedure into a variable, which will later be used to insert into a table.

    DECLARE @Body varchar(50)

    EXEC @Body = dbo.usp_GetSupplyUtil '1A2345'

    SELECT Body

    dbo.usp_GetSupplyUtil '1A2345' does give me the correct results but doesn't store in @Body

  • please try

    SELECT @body

  • Assuming that the procedure returns a resultset, in which case, the results can only be stored in a temporary/permanent table or a table variable. So, you have do something like...

    CREATE TABLE #Body( SomeColumn VARCHAR(50) )

    INSERT #Body

    EXECUTE dbo.usp_GetSupplyUtil '1A2345'

    SELECT * FROM #Body

    --Ramesh


  • Does the proc select the data, or is it an output parameter, or a "return value"? Depending on which of these it is, there are ways to get what you need, but it depends on which one it is.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • [font="Verdana"]This isn't the recommended way of returning values from procedures. Try using an output parameter. The return value is really meant to be used for error status numbers.[/font]

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

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