Link to home
Start Free TrialLog in
Avatar of Endelm
Endelm

asked on

SQL OUT Parameter

Hi,

I'm using Microsoft SQL 2005.

create procedure dbo.Myproc
@p1 int,
@p2 int out
as
set  @p2 = @p1*10

declare @myval int
exec dbo.Myproc 1, @myval
select @myval

How come I always get NULL when I run this thing above?

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of twoboats
twoboats

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deroby
deroby

you need to tell the EXEC that @myval is an OUTPUT variable :

create procedure dbo.Myproc
@p1 int,
@p2 int output
as
set  @p2 = @p1*10

go


declare @myval int
exec dbo.Myproc 1, @myval output
select @myval
Avatar of Endelm

ASKER

Oh my god, OF COURSE!!! :)
easily missed
You forgot to put the OUTPUT identifier after the return variable.  Try:

declare @myval int
exec dbo.Myproc 1, @myval OUTPUT
select @myval

HTH,
Charly
Aw man, that's what I get for not refreshing my browser...  Anyway, glad you figured it out.

--Charly