27

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
  • 2
    Looks like the sum of all those sizes is bigger than MAX int.... Commented Aug 3, 2009 at 15:10

1 Answer 1

58

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%'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.