Just now I was getting this error when running a stored procedure:
Arithmetic overflow error converting varchar to data type numeric.
I located the line where that error was coming from and this is the code on that line:
SELECT @AF_MIN_3L = LEFT(MIN([A-F Est_CY]), 6) - 0.000001 FROM #Ent_AF_3
Earlier in the stored procedure, I declared @AF_MIN_3L as data type FLOAT, created the temp table #Ent_AF_3 and in doing so, made the column [A-F Est_CY] data type FLOAT. Is the following code creating a non-FLOAT value?
LEFT(MIN([A-F Est_CY]), 6) - 0.000001
I hope it's a simple casting issue and all I have to do is something like this:
LEFT(MIN(CAST([A-F Est_CY] AS FLOAT)), 6) - CAST(0.000001 AS FLOAT)
I didn't want to run the whole procedure again without being sure I fixed the issue. Thanks for any help.
SELECT @AF_MIN_3L = CAST(LEFT(MIN([A-F Est_CY]), 6) AS float ) - 0.000001 FROM #Ent_AF_3but I guess it depends on what it is you actually want to accomplish.MIN(CAST(LEFT([A-F Est_CY], 6) AS FLOAT))? Take the left 6 characters, convert to float, and find the minimum?select @a=-0.00001leads toselect @a>-1E-05andselect LEFT(@a, 6)>-1e-00