Why SQL Server throws Arithmetic overflow error converting int to data type numeric?

Junior Mayhé picture Junior Mayhé · Jan 13, 2010 · Viewed 172.7k times · Source

I have an error being thrown by SQL Server Management Studio when running this code:

declare @percentage numeric(3,2)
set @percentage = cast(15 as numeric(3,2))

but when I change numeric declaration to

declare @percentage numeric(4,2)
set @percentage = cast(15 as numeric(4,2))

everything goes fine.

Is there a limitation for numeric data type?

Answer

Joe picture Joe · Jan 13, 2010

Numeric defines the TOTAL number of digits, and then the number after the decimal.

A numeric(3,2) can only hold up to 9.99.