2011-04-28 247 views
4

環境是SQL Server 2005

有沒有辦法在獲取存儲過程的輸出參數時使用命名參數?目前,我對輸出參數的瞭解非常有限。看起來我必須按照存儲過程中的聲明來使用它們。即如果我做了exec test @rich output,@bob output這個電話就會爆炸。我怎樣才能讓訂單成爲任意的?謝謝SQL Server輸出參數

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 

回答

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

或者,如果你喜歡

EXEC test @mark = @rich OUTPUT, @ID = @bob OUTPUT 
1
declare @bob as int 
declare @rich as char(20) 
exec test 
     @mark = @rich output, 
     @id = @bob output 
select @bob,@rich 
+0

的三個答案我目前看到的是等效的,但把每個參數在一個單獨的線上這是一個更清晰的答案。 – 2011-04-28 14:18:40

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