Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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 1, 2013 12:31 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, March 20, 2015 8:32 AM
Points: 253, Visits: 758
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 1, 2013 12:34 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:03 PM
Points: 14,312, Visits: 37,385
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!
Post #1437569
Posted Monday, April 1, 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 @ 3:42 PM
Points: 22,958, Visits: 36,554
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 1, 2013 12:54 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, March 20, 2015 8:32 AM
Points: 253, Visits: 758
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