Sql Server: Arithmetic Overflow Error Converting Expression to Data Type Int

SQL Server: arithmetic overflow error converting expression to data type int in where condition

Cast before adding:

select *
from orders
where orderid > @id and orderid < cast(@id as bigint) + 1000 ;

Or better yet, declare @id to be a bigint.

How to solve error Arithmetic overflow error converting expression to data type int?

seems like the result of sum() overflows, how about cast the r to bigint
before sum the result up :

SELECT x, y, z, sum(cast(r as bigint)) AS R 
FROM data_table
WHERE [start_time] >= convert(datetime, '2022-02-03')
AND [end_time] <= CONVERT(datetime, '2022-02-07')
GROUP BY x, y, z

db<>fiddle here

SQL COUNT overflow

Use COUNT_BIG

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

On Insert: Arithmetic overflow error converting expression to data type int

An int probably isn't the best data type for a phone number - you don't need to do any arithmetic on phone numbers, so why use a numerical data type? Store it as a string (or varchar in SQL).

Also, if you did need to store a value as an int, 2,147,483,647 is the maximum - anything higher would "overflow", hence the error you're getting. A long (or bigint in SQL) would allow values up to 9,223,372,036,854,775,808.



Related Topics



Leave a reply



Submit