微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQL Server 返回“Arithmetic overflow error converting expression to data type int”

如何解决SQL Server 返回“Arithmetic overflow error converting expression to data type int”

对于大于INT最大值 (2,147,483,647) 的值,您需要使用COUNT_BIG (*)。

SELECT COUNT_BIG(*) AS [Records], SUM(t.Amount) AS [Total]
FROM   dbo.t1 AS t
WHERE  t.Id > 0
       AND t.Id < 101;

如果它发生在 中SUM,您需要转换AmountBIGINT.

SELECT COUNT(*) AS [Records], SUM(CONVERT(BIGINT, t.Amount)) AS [Total]
FROM   dbo.t1 AS t
WHERE  t.Id > 0
       AND t.Id < 101;

解决方法

当我运行这个命令时SUM()

SELECT COUNT(*) AS [Records],SUM(t.Amount) AS [Total]
FROM   dbo.t1 AS t
WHERE  t.Id > 0
       AND t.Id < 101;

我越来越,

Arithmetic overflow error converting expression to data type int.

知道它的原因是什么吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。