我有一个字段是varchar类型.
我现在想要取出所有该字段为0-9组成的的记录,删除不是0-9组成的记录.

解决方案 »

  1.   

    ISNUMERIC
    确定表达式是否为一个有效的数字类型。
      

  2.   

    --取:
    select * from tablename where isnumeric(columnname) = 1--删:
    delete from tablename where isnumeric(columnname) = 0
      

  3.   

    --取:
    select * from tablename where isnumeric(columnname) = 1 and charindex('.',columnname) = 0--删:
    delete from tablename where isnumeric(columnname) = 0 and charindex('.',columnname) > 0
      

  4.   

    --删:
    delete from tablename where isnumeric(columnname) = 0 or columnname like '%.%' --or
      

  5.   

    非数字:isnumeric(字段)=0
    数字:isnumeric(字段)=1
      

  6.   

    isnumeric不能满足这个需求。要用PATINDEX。
    ----------------------------------------------------
    SELECT PATINDEX('%[^0-9]%','123')
    , PATINDEX('%[^0-9]%','123.25')
    , PATINDEX('%[^0-9]%','12AB3')
                                        
    ----------- ----------- ----------- 
    0           4           3(1 row(s) affected)返回值大于零的都表示含有非0-9的字符。