Arithmetic overflow on column sum in sql server

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%'

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.

  • sp_add_jobstep in SQL Server
  • Counting Items based on First Month Sold
  • sql server linked server to oracle returns no data found when data exists
  • One database to log in, use different database depending on person
  • How to make a table Read Only in SQL Server?
  • SqlException was Unhandled
  • One Solution collect form web for “Arithmetic overflow on column sum in sql server”

    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%'
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.