Search code examples
sqlsql-serversql-server-2000

Arithmetic overflow error for type in Sql Server 2000


In an SQL SERVER 2000 table,there is a column called Kpi of float type. when try to convert that column to varchar(cast(kpi as varchar(3))),It gives an error

Msg 232, Level 16, State 2, Line 1
Arithmetic overflow error for type varchar, value = 26.100000.

The thing is the column has only one distinct value and that is 26.1. I can not understand why does it show error when converting it into varchar!


Solution

  • your error has triggered by full stop in 26.1.

    you have applied this command:

    cast(kpi as varchar(3))
    

    First: change cast from varchar(3) to varchar(4) (to get the first value after full stop)

    So you'll have:

    This line convert value 26.10000000 in 26.1

    Then you apply varchar(26.1) not correct!

    Varchar type wants only integer value as size.

    Why you apply the last varchar?? I think you must to remove the external varchar and leave only cast function