create table myTable
(id int identity(1,1) not null,
fname varchar(20),
lname varchar(20)
)
go
insert myTable
values('fadf','fadfasdf')
gocreate procedure myPr
(
@Id int output,
@fName varchar(20),
@lName varchar(20)
)
as
select @ID=TableID
from Employee
where fname=@fname
and lname=@lnamego
declare @myID int
exe mypr 'fadf','fadfasdf',@myId output
(id int identity(1,1) not null,
fname varchar(20),
lname varchar(20)
)
go
insert myTable
values('fadf','fadfasdf')
gocreate procedure myPr
(
@Id int output,
@fName varchar(20),
@lName varchar(20)
)
as
select @ID=TableID
from Employee
where fname=@fname
and lname=@lnamego
declare @myID int
exe mypr 'fadf','fadfasdf',@myId output
@out int output
AS
set @out=34
go
declare @out int
exec aa @out output
select @out
OUTPUT 参数允许外部过程、批处理或多条 Transact-SQL 语句访问在过程执行期间设置的某个值。下面的示例创建一个存储过程 (titles_sum),并使用一个可选的输入参数和一个输出参数。首先,创建过程:USE pubs
GO
IF EXISTS(SELECT name FROM sysobjects
WHERE name = 'titles_sum' AND type = 'P')
DROP PROCEDURE titles_sum
GO
USE pubs
GO
CREATE PROCEDURE titles_sum @@TITLE varchar(40) = '%', @@SUM money OUTPUT
AS
SELECT 'Title Name' = title
FROM titles
WHERE title LIKE @@TITLE
SELECT @@SUM = SUM(price)
FROM titles
WHERE title LIKE @@TITLE
GO
(id int identity(1,1) not null,
fname varchar(20),
lname varchar(20)
)
go
insert #myTable
values('fadf','fadfasdf')
gocreate procedure #myPr
(
@fName varchar(20),
@lName varchar(20),
@myId int output
)
as
select @myId=id from #myTable where fname=@fname and lname=@lname
godeclare @myID int
exec #mypr 'fadf','fadfasdf',@myId output
print @myID
(id int identity(1,1) not null,
fname varchar(20),
lname varchar(20)
)
go
insert #myTable
values('fadf','fadfasdf')
gocreate procedure #myPr
(
@fName varchar(20),
@lName varchar(20),
@myId int output
)
as
select @myId=id from #myTable where fname=@fname and lname=@lname
godeclare @myID int
exec #mypr 'fadf','fadfasdf',@myId output
print @myID
1. create procedure proc1 --返回參數
(
@para1 paratype(paralen),
@para2 paratype(paralen),
@para3 paratype(paralen) output
)
as2.
create procedure proc2 --返回記錄
(@para...
)
as
set nocount on
...
select * from tableA3. 調用:
exec proc1(@para1,@para2,@para3 output)
set nocount off
go
exec 过程名 @a outputselect @a
exec @a=过程名select @a