SQL Server输出参数

时间:2011-04-28 13:59:56

标签: sql sql-server sql-server-2005

环境是SQL Server 2005

在获取存储过程的输出参数时,有没有办法使用命名参数?目前,我对输出参数的了解非常有限。看起来我必须按照它们在存储过程中的声明顺序使用它们。也就是说,如果我exec test @rich output,@bob output,那话就会爆炸。我怎么能让订单成为仲裁?谢谢

create procedure test
  @ID as INT output
 ,@mark as char(20) output
as

  select @ID = 5,@mark='test'
go
declare @bob as int
declare @rich as char(20)
exec test @bob output, @rich output
select @bob,@rich

3 个答案:

答案 0 :(得分:4)

EXEC test @ID = @bob OUTPUT, @mark = @rich OUTPUT

或者,如果您愿意

EXEC test @mark = @rich OUTPUT, @ID = @bob OUTPUT  

答案 1 :(得分:1)

declare @bob as int
declare @rich as char(20)
exec test
        @mark = @rich output,
        @id = @bob output
select @bob,@rich

答案 2 :(得分:0)

而不是positional使用named parameters

declare @bob as int
declare @rich as char(20)


exec test @ID = @bob output, @mark = @rich output
select @bob,@rich

exec test  @mark = @rich OUTPUT,@ID = @bob output
select @bob,@rich