Getting an error converting varchar to float.
Have a table (not of my making) with column result
, having varchar data. I\'d like to convert to float to
Check this out:
http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html
Basically, there are some known issues / oddities with the ISNUMERIC function. The author of that article suggests creating a new function and using that instead of ISNUMERIC. I tested it with the 1,0
value you suggested and it seems to work.
CREATE FUNCTION dbo.isReallyNumeric
(
@num VARCHAR(64)
)
RETURNS BIT
BEGIN
IF LEFT(@num, 1) = '-'
SET @num = SUBSTRING(@num, 2, LEN(@num))
DECLARE @pos TINYINT
SET @pos = 1 + LEN(@num) - CHARINDEX('.', REVERSE(@num))
RETURN CASE
WHEN PATINDEX('%[^0-9.-]%', @num) = 0
AND @num NOT IN ('.', '-', '+', '^')
AND LEN(@num)>0
AND @num NOT LIKE '%-%'
AND
(
((@pos = LEN(@num)+1)
OR @pos = CHARINDEX('.', @num))
)
THEN
1
ELSE
0
END
END
GO