error converting varchar to float

前端 未结 3 1262
小鲜肉
小鲜肉 2020-12-20 07:32

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

3条回答
  •  伪装坚强ぢ
    2020-12-20 08:04

    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 
    

提交回复
热议问题