ainasiart
ainasiart

Reputation: 382

SQL Server 2014 error: Arithmetic overflow error converting expression to data type int

Can you explain this error in SQL Server 2014 Express?

SELECT FLOOR(21474837 * 100)    -- doesn't work
SELECT FLOOR(214748370 * 10)    -- doesn't work
SELECT FLOOR(2147483700)        -- works
SELECT FLOOR(21474837 / 0.01)   -- works

The number 21474837 is chosen because inferior numbers have no problem neither

Upvotes: 1

Views: 681

Answers (1)

S3S
S3S

Reputation: 25112

That's because FLOOR returns same datatype as the input, which is INT in your case. Add some decimals and it will fix it.

SELECT FLOOR(21474837.00 * 100)    

The largest INT number is 2147483647 and 21474837 * 100 = 2147483700, which is 53 too many

Upvotes: 3

Related Questions