SQL COUNT overflow

SqlSql ServerCountOverflow

Sql Problem Overview


Here is my query:

SELECT COUNT(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0

Here is the result:

> Msg 8115, Level 16, State 2, Line 1 > > Arithmetic overflow error converting expression to data type int.

The table has 4 billion rows. I don't expect this query to be fast, but after about 5mins, it fails with an overflow error. Is there a COUNT function for bigger data than int?

Thanks.

Sql Solutions


Solution 1 - Sql

Use COUNT_BIG

SELECT COUNT_BIG(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0

Solution 2 - Sql

  SELECT COUNT_BIG(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity = 0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser593062View Question on Stackoverflow
Solution 1 - SqlpstrjdsView Answer on Stackoverflow
Solution 2 - SqlSanjeevakumar HiremathView Answer on Stackoverflow