You are here: Blog - Troubleshooting

Error converting data type varchar to float

Under certain conditions, if you try to convert or cast a variable to Float you might get the below error message:
"Error converting data type varchar to float."

Most probably you are getting this error message because the variable you are trying to convert is "not qualified" for the conversion.

In order to better understand, consider the following example:

--Declare variable
DECLARE @tmpValue VARCHAR(20);
SELECT @tmpValue='10.10.10';

--Try to cast the variable to FLOAT
SELECT CAST(@tmpValue AS FLOAT) AS ConvertedValue;
GO

Output:
Msg 8114, Level 16, State 5, Line 6
Error converting data type varchar to float.

Resolution: Correct the variable's value and try to cast/convert it again.