ISNUMERIC('07213E71') = True?

后端 未结 5 2093
暖寄归人
暖寄归人 2020-12-17 16:59

SQL is detecting that the following string ISNUMERIC:

\'07213E71\'

I believe this is because the \'E\' is being classed as a mathmatical symbol.

5条回答
  •  佛祖请我去吃肉
    2020-12-17 17:34

    I have encountered the same problem. IsNumeric accepts "$, €, +, -, etc" as valid inputs and Convert function throws errors because of this. Using "LIKE" SQL statement fixed my problem. I hope it'll help the others

    SELECT UnitCode, UnitGUID, Convert(int, UnitCode) AS IntUnitCode
          FROM [NG_Data].[NG].[T_GLB_Unit]  
         WHERE ISNULL(UnitType,'') <>'Department'
           AND UnitCode NOT LIKE '%[^0-9]%'
      ORDER BY IntUnitCode
    

    PS: don't blame me for using "UnitCode" as nvarchar :) It is an old project :)

提交回复
热议问题