weight
1.1
1g
2
3
字段weight的数据类型是varchar,我想查询weight值大于1的记录,要求能跳过不是数字的数据,比如1g就跳过,sql语句或者存储过程都行

解决方案 »

  1.   

      weight not like '%[a-z]%'
      

  2.   

    ------------------------------------
    -- Author: flystone  
    -- Version:V1.001  
    -- Date:2010-02-06 18:02:34
    -------------------------------------- Test Data: ta
    If object_id('ta') is not null 
        Drop table ta
    Go
    Create table ta(weight varchar(10))
    Go
    Insert into ta
     select '1.1' union all
     select '1g' union all
     select '2' union all
     select '3' union all
     select '0.2' 
    Go
    --Start
    Select * from ta where weight not like '%[a-z]%' and cast(weight as numeric(12,2)) > 1
    --Result:
    /*weight     
    ---------- 
    1.1
    2
    3(所影响的行数为 3 行)
    */
    --End