从SQL Server存储过程返回bigint

bac*_*ack 3 c# sql stored-procedures sql-server-2008-r2

我在SQL Server中编写了一个存储过程,它将返回一个Bigint

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

    return @startid     
end
Run Code Online (Sandbox Code Playgroud)

但是在返回价值的同时我得到了一个例外

将表达式转换为数据类型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();
Run Code Online (Sandbox Code Playgroud)

如果没有返回值,我如何将值分配给"RetVal"我的_lookup变量.

Gor*_*off 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;
Run Code Online (Sandbox Code Playgroud)

使用return存储过程是否成功.

你可以这样称呼:

declare @startid bigint;

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

select @startid;
Run Code Online (Sandbox Code Playgroud)