MSSQL: Arithmetic overflow error converting expression to data type int

来源:互联网 发布:郫县兼职教师招聘知乎 编辑:程序博客网 时间:2024/05/09 10:19

今天 某老板要求提供现在项目的在过去的一年内,每个月的流量统计

由于数据的数据量比较的大, 当时每个数据的字段是用int来设计的,  int最大表示的数据是2B。

但是我们的系统每天的数据量大概是20M,一个月就是6B左右。


所以 一开始直接用sum计算的时候就出了问题, 显示 Arithmetic overflow error converting expression to data type int 错误

所以 在sum之前,先进行类型的转化

cast(accepted as bigint),或者cast(accepted as numeric(38,0)或者cast(accepted as decimal)

 然后再

sum(cast(accepted as bigint)) accepted


问题就解决了,



原创粉丝点击