0
votes

Can someone help me understand why the first one does not work and the second one works

  1. SELECT CONVERT(numeric(11, 2), NULLIF('4702137480', '')) / 100.00.
    Error Message:

    Msg 8115, Level 16, State 8, Line 1
    Arithmetic overflow error converting varchar to data type numeric.

  2. SELECT CONVERT(numeric(12, 2), NULLIF('4702137480', '')) / 100.00.
    Result 47021374.80000000

My understanding was 11, 2 meant a total of 11 and the last two are after the decimal place. As the example only has 10 digits I don't understand why it does not work.

2

2 Answers

1
votes

Because numeric(11, 2) means 9 digits before decimal point and 2 digits after. Totally 11 digits.

1
votes

Because first its convert it to numeric and after that divided to 100 so numeric(11,2) means 9 digit and you have 10 digit it is cause of error