?
Solved

SQL OUT Parameter

Posted on 2007-07-24
6
Medium Priority
?
6,450 Views
Last Modified: 2008-10-06
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?
0
Comment
Question by:Endelm
6 Comments
 
LVL 14

Accepted Solution

by:
twoboats earned 2000 total points
ID: 19557143
exec dbo.Myproc 1, @myval output
0
 
LVL 11

Expert Comment

by:deroby
ID: 19557163
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
0
 

Author Comment

by:Endelm
ID: 19557181
Oh my god, OF COURSE!!! :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:twoboats
ID: 19557189
easily missed
0
 
LVL 1

Expert Comment

by:dleehanson
ID: 19557275
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
0
 
LVL 1

Expert Comment

by:dleehanson
ID: 19557284
Aw man, that's what I get for not refreshing my browser...  Anyway, glad you figured it out.

--Charly
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question