2010-08-02 23 views

回答

0

您應該使用輸出參數的存儲過程:

DECLARE @output1 INT 
EXEC [proc] @input, @output1 OUTPUT 

PRINT @output1 
2
DECLARE @ret INT 
DECLARE @output INT 

EXEC @ret = [proc] @input, @output OUTPUT 

SELECT @ret, @output 

@ret是返回值:RETURN -1
@output是一個可分配的variab le任何類型:SET @output = 123

0

函數是執行常用計算的好地方。

CREATE FUNCTION dbo.ufnAddIntegers 
    (@pint1 as int, @pint2 as int) 
RETURNS int 
AS 
BEGIN 
    return @pint1 + @pint2 
END 
go 

declare @intResult int 
set @intResult = dbo.ufnAddIntegers(3, 4) 
select Result = @intResult 

/* 
Result 
----------- 
7 
*/ 
+0

感謝@peterellis其良好的解決方案。輸入 函數和存儲過程之間的區別 – shmandor 2010-08-03 09:22:35