【问题标题】:Arithmetic overflow on column sum in sql serversql server中列总和的算术溢出
【发布时间】:2009-08-03 15:07:10
【问题描述】:

我正在尝试获取列总数,但是当我运行此查询时,我收到以下错误。有什么建议吗?

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.

【问题讨论】:

  • 看起来所有这些尺寸的总和大于 MAX int....

标签: sql-server


【解决方案1】:

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

将它们投射到BIGINT

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    相关资源
    最近更新 更多