开发者

SQL Server Output Parameters

开发者 https://www.devze.com 2023-03-01 13:14 出处:网络
Environment is SQL Server 2005 Is there a way to use named parameters when getting the output parameters of a stored proc? Currently, my knowledge of output parameters is very limited. It looks like

Environment is SQL Server 2005

Is there a way to use named parameters when getting the output parameters of a stored proc? Currently, my knowledge of output parameters is very limited. It looks like I have to use them in order of their declaration in the stored proc. i.e., if I did exec test @rich output,@bob output the call would blow up. How can I have the 开发者_C百科order be arbitary? Thank you

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


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

Or, if you prefer

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


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


instead of positional use 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号