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

解决方案 »

  1.   

    create proc aa
            @out int output
    AS
      set @out=34
    go
    declare @out int
    exec aa @out output
    select @out      
      

  2.   

    OUTPUT表明参数是返回参数。该选项的值可以返回给 EXEC[UTE]。使用 OUTPUT 参数可将信息返回给调用过程。Text、ntext 和 image 参数可用作 OUTPUT 参数。使用 OUTPUT 关键字的输出参数可以是游标占位符。D. 使用 OUTPUT 参数
    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
      

  3.   

    exec @GetReturnValue= procedureName(@parameter1....)
      

  4.   

    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
    (
    @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
      

  5.   

    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
    (
    @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 
      

  6.   

    想返回參數, 還是返回記錄?
    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
      

  7.   

    declare @a int
    exec 过程名 @a outputselect @a
      

  8.   

    如果是return:declare @a int
    exec @a=过程名select @a