Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Why is Output parameter null? Expand / Collapse
Author
Message
Posted Monday, April 01, 2013 12:31 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 6:40 AM
Points: 230, Visits: 697
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.
Post #1437567
Posted Monday, April 01, 2013 12:34 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:39 PM
Points: 12,749, Visits: 31,114
I believe when you call the procedure, you need to mark the parameter as output also:
exec Testout 'Y', @p2 OUTPUT





Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1437569
Posted Monday, April 01, 2013 12:53 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:25 PM
Points: 22,525, Visits: 30,288
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;





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437575
Posted Monday, April 01, 2013 12:54 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 6:40 AM
Points: 230, Visits: 697
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.
Post #1437576
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse