2014-09-12 169 views
3

我已經寫在SQL Server中的存儲過程,它會返回一個Bigint返回BIGINT存儲過程

alter procedure [dbo].adding 
    @one bigint, 
    @two bigint, 
    @startid bigint output 
as 
begin 
    set @startid = @one + @two 

    return @startid  
end 

但在返回值我得到一個異常

算術溢出錯誤將表達式轉換爲數據類型int

任何人都可以幫我解決這個問題嗎?

在此先感謝

注:以上查詢是不是到底是哪,我使用

更新了相同的過程:

我有一個像下面的代碼

_lookupId = cmdInsert.Parameters.Add("RetVal", SqlDbType.BigInt); 
         _lookupId.Direction = ParameterDirection.ReturnValue; 

         _procIn01 = cmdInsert.Parameters.Add("@idCount", SqlDbType.VarChar, 500); 
         cmdInsert.Parameters["@idCount"].Value = idCount; 
         _procIn01.Direction = ParameterDirection.Input; 

         _procIn02 = cmdInsert.Parameters.Add("@requestFrom", SqlDbType.VarChar, 100); 
         cmdInsert.Parameters["@requestFrom"].Value = clientId; 
         _procIn02.Direction = ParameterDirection.Input; 

         _pramOut = cmdInsert.Parameters.Add("@startID", SqlDbType.BigInt); 
         _pramOut.Direction = ParameterDirection.Output; 
         cmdInsert.ExecuteScalar(); 

無法返回值如何分配t他的價值是「RetVal」我的_lookup變量。

+0

程序返回狀態。函數返回值。 – 2014-09-12 12:12:51

+0

你實際上不必返回你的輸出變量,只是設置它應該足以讓輸出填充你的應用程序 – Kritner 2014-09-12 12:25:24

回答

6

過程返回一個狀態值,它始終是一個整數。你可以通過設置它返回從存儲過程的值:

alter procedure [dbo].adding 
    -- add the parameters for the stored procedure here 
    @one bigint, 
    @two bigint, 
    @startid bigint output 
as 
begin 
    -- set nocount on added to prevent extra result sets from 
    -- interfering with select statements. 

    set @startid = @one + @two  
end; 

使用return存儲過程是否成功。

你可以調用此方法是這樣的:

declare @startid bigint; 

exec dbo.adding(1, 2, @startid output); 

select @startid; 
+0

我已更新帖子你可以幫我 – Backtrack 2014-09-12 12:58:41

+0

@Backtrack。 。 。以下是如何在C#中編寫代碼的示例:http://stackoverflow.com/questions/10905782/using-stored-procedure-output-parameters-in-c-sharp。 – 2014-09-12 13:26:52

+0

明白了,謝謝:) – Backtrack 2014-09-13 07:52:19

1

Sotred procedure return answer是顯示sp是否成功的整數
如果你想要得到一個輸出值,你不能用它來得到一個big int數 出out put parameter,那麼你可以使用帶出變量選擇,例如,
使用電話

Select @[email protected] 

現在獲取輸出Execute Scalar指揮方法。