Arithmetic overflow on column sum in sql server

醉酒当歌 提交于 2019-12-08 14:35:58

问题


I'm trying to get a column total but when i run this query i get the following error. Any advice?

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.

回答1:


While all your sizes can fit into INT (up to 2^31 - 1), their SUM cannot.

Cast them into BIGINT:

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


来源:https://stackoverflow.com/questions/1222877/arithmetic-overflow-on-column-sum-in-sql-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!