Arithmetic overflow error converting varchar to data type numeric with column insert

时间:2015-07-28 16:12:45

标签: sql-server

I get the following error above when I try to insert this column into the database. What do I need to do fix this problem?

INSERT INTO School(GPA) 

GPA = CASE 
        WHEN ISNUMERIC(LEFT(LTRIM(HS.XAPPLAPPMISC2), 8.2)) = 1 
          THEN LEFT(LTRIM(HS.XAPPLAPPMISC2), 8.2)
          ELSE NULL
      END,
FROM HighSchool HS 

1 个答案:

答案 0 :(得分:0)

You are getting this error as I presume the column you're dealing with is int?

You could convert/cast the column to big int before doing your processing on it:

WHEN ISNUMERIC(LEFT(LTRIM(CONVERT(BIGINT,HS.XAPPLAPPMISC2)), 8.2)) = 1 THEN
                            LEFT(LTRIM(CONVERT(BIGINT,HS.XAPPLAPPMISC2)), 8.2)

You can see the microsoft documentation on this here:https://msdn.microsoft.com/en-GB/library/ms187745.aspx The table shows the ranges of each type.

I hope this helps.

Another thing is that you're select left 8.2 which will ultimately give you left 8 unless I'm mistaken?