2009-08-03 22 views
18

我试图获得列总数,但是当我运行此查询时出现以下错误。有什么建议?SQL Server中列总和的算术溢出

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. 
+3

什么是[尺寸]的数据类型? – 2009-08-03 15:08:20

+1

数据类型为int – 2009-08-03 15:09:55

回答

35

虽然所有的尺寸可以放入INT(最多2^31 - 1),其SUM不能。

扔在BIGINT

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