Can you call a SQL Stored Procedure that returns a record set and have those values loaded into vari

Posted by codingguy3000 on Stack Overflow See other posts from Stack Overflow or by codingguy3000
Published on 2010-03-18T20:20:59Z Indexed on 2010/03/18 20:51 UTC
Read the original article Hit count: 420

Filed under:
|

Hello fellow stackers

Please consider the following SQL Server table and stored procedure.

create table customers(cusnum int, cusname varchar(50))

insert into customers(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.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2005