Why is Output parameter null?

  • Can someone explain why @p2 is null/empty?

    begin try drop procedure TestOut end try begin catch end catch

    go

    create procedure TestOut

    @P1 varchar(256),

    @p2 varchar(MAX) OUTPUT

    as

    if @p1 = 'Y'

    set @p2 = 'Yes'

    else

    set @p2 = 'Not Y'

    go

    /*

    declare @p2 varchar(max)

    exec Testout 'Y', @p2

    if @p2 IS NULL

    print 'nothing'

    else

    print 'P2 is ' + @p2

    */

    Thanks

    <><
    Livin' down on the cube farm. Left, left, then a right.

  • I believe when you call the procedure, you need to mark the parameter as output also:

    exec Testout 'Y', @p2 OUTPUT

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell is correct.

    create procedure TestOut

    @P1 varchar(256),

    @p2 varchar(MAX) OUTPUT

    as

    if @p1 = 'Y'

    set @p2 = 'Yes'

    else

    set @p2 = 'Not Y'

    go

    declare @p2 varchar(max)

    exec Testout 'Y', @p2 output

    if @p2 IS NULL

    print 'nothing'

    else

    print 'P2 is ' + @p2

    drop procedure TestOut;

  • argh!! Documentation example shows that as well. Sorry I didn't see it before.

    <><
    Livin' down on the cube farm. Left, left, then a right.

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

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