Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Msg 232,16级,状态3,第5行int型算术溢出错误_Sql_Sql Server_Sql Server 2008_Tsql_Msbi - Fatal编程技术网

Sql Msg 232,16级,状态3,第5行int型算术溢出错误

Sql Msg 232,16级,状态3,第5行int型算术溢出错误,sql,sql-server,sql-server-2008,tsql,msbi,Sql,Sql Server,Sql Server 2008,Tsql,Msbi,如何找出两个变量之间的差异 error is Msg 232, Level 16, State 3, Line 5 Arithmetic overflow error for type int, value = -39827814763.955299. Msg 232, Level 16, State 3, Line 12 Arithmetic overflow error for type int, value = -39827814763.950142. 查询如下。。 短暂性脑缺血发作

如何找出两个变量之间的差异

error is Msg 232, Level 16, State 3, Line 5
Arithmetic overflow error for type int, value = -39827814763.955299.

Msg 232, Level 16, State 3, Line 12
Arithmetic overflow error for type int, value = -39827814763.950142.
查询如下。。 短暂性脑缺血发作

上面的值是十进制的,您试图将其存储为INT。INT可以将数字存储在以下范围内

-2,147,483,648 to 2,147,483,647
您可以使用BIGINT来克服溢出

declare  @sql BIGINT 
declare @sql1 BIGINT 
declare @sql3 BIGINT 
但是,对于上述数据类型,您正在失去精度,如果您想要精度,请使用如下所示的数字

 declare  @sql numeric(22,6)

SUM中表达式的类型决定了案例中的返回类型sfg.amount。例如,在执行如下求和之前,可以将其强制转换为BIGINT:

SELECT SUM( CAST( sfg.amount AS BIGINT )) ....

看起来int太小了。改为使用最大十进制数(如果需要大整数,则使用bigint)。
 declare  @sql numeric(22,6)
SELECT SUM( CAST( sfg.amount AS BIGINT )) ....