SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why is Output parameter null?


Why is Output parameter null?

Author
Message
Tobar
Tobar
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1039 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.
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71104 Visits: 40924
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!
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94115 Visits: 38955
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;




Cool
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)
Tobar
Tobar
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1039 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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search