Please consider the following SQL Server table and stored procedure.
create table customers(cusnum int, cusname varchar(50))
insert into custom开发者_如何转开发ers(cusnum, cusname) values(1, 'Ken')
insert into customers(cusnum, cusname) values (2, 'Violet') --The Wife
create procedure getcus
@cusnum int
as
Begin
select cusname
from customers (nolock)
where cusnum = @cusnum
End
You know how you can write T-SQL code like this:
declare @cusname varchar(50)
select @cusname = cusname
from customers
where cusnum = 1
Can I do this with my stored procedure?
for example the code would look like this:
declare @cusnum int
declare @cusname varchar(50)
set @cusnum = 1
exec @cusname = cusname pbogetcus @cusnum
Thanks in advance.
No, you can't return values like that.
You need to use OutputParameters: MSDN.
EDIT:
This might be a better link:
SQL Team
Check out the section about midway down: Using OUTPUT variables
精彩评论