Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : Arithmetic overflow error converting numeric to data type varchar

Error : Arithmetic overflow error converting numeric to data type varchar.

Getting error at this line why and what should be changed?

CONVERT(VARCHAR(8),CONVERT(DECIMAL(8,4),((CurrentLoans.Price - PreviousLoans.Price) / PreviousLoans.Price) * 100)) 
like image 667
Neo Avatar asked Dec 21 '11 15:12

Neo


1 Answers

Here's at least one issue:

CONVERT(VARCHAR(8),CONVERT(DECIMAL(8,4))

The Decimal(8,4) indicates 8 numeric digits, 4 to the right of the decimal. This does NOT account for the actual decimal character, so you potentially have a value like:

1234.5678

which is a valid Decimal(8,4) but won't fit in a varchar(8).

like image 55
JNK Avatar answered Oct 31 '22 09:10

JNK