Search code examples
sql-servervariablestypesnumeric

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


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?


Solution

  • 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.