Home Forums SQL Server 2008 T-SQL (SS2K8) Store result of stored procedure into a xml/nvarchar(max) variable RE: Store result of stored procedure into a xml/nvarchar(max) variable

  • Just posting an answer to this forum just in case anyone else hits the problem.

    The return value from a stored procedure is always an integer and it was never intended to pass back programmatic values. They are for status and are used for communicating things like warnings and errors within the data or code. By convention, a 0 (zero) means everything is OK.

    You can pass back integer values in the 'return' statement by passing an optional integer parameter to RETURN.

    [font="Courier New"]

    CREATE PROCEDURE Tryout2

    AS

    RETURN (4)

    GO

    --The variable you assign this to  must be declared in the batch, stored procedure, or function before it is used in an EXECUTE statement.

    DECLARE @Return INT

    EXECUTE @Return =Tryout2

    SELECT @Return[/font]

    When you google for '@return_status' you'll see that it is an optional integer variable that stores the return status of a module.

    In order to pass XML, or any other type of data, from a stored procedure you must use Outout Variables as has already been said. They are extraordinarily useful.

    Best wishes,
    Phil Factor