加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – sql server中的列总和算术溢出

发布时间:2020-12-12 16:13:47 所属栏目:MsSql教程 来源:网络整理
导读:我试图得到一个列,但是当我运行这个查询我得到以下错误.任何建议? SELECT SUM(Size) as totalFROM AllDocsWhere DirName LIKE 'sites/test/test%'ERROR:Msg 8115,Level 16,State 2,Line 1Arithmetic overflow error converting expression to data type int.
我试图得到一个列,但是当我运行这个查询我得到以下错误.任何建议?
SELECT SUM(Size) as total
FROM  AllDocs
Where DirName LIKE 'sites/test/test%'


ERROR:
Msg 8115,Level 16,State 2,Line 1
Arithmetic overflow error converting expression to data type int.
Warning: Null value is eliminated by an aggregate or other SET operation.

解决方法

虽然所有的尺寸都可以适应于INT(最多2 ^ 31 – 1),但它们的SUM不能.

把它们变成BIGINT:

SELECT  SUM(CAST(Size AS BIGINT)) as total
FROM    AllDocs
WHERE   DirName LIKE 'sites/test/test%'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读