比如 t1 表有这样的一个字段 c , c 字段中有这样的值,每行一个。
-------------------------------------------------------------
aaa
bcds
a1

^%
ew1
344
__
213_21
a_2
d
ddd
电风扇
-------------------------------------------------------------
如何搜索出下面这些字段呢?

^%
电风扇

解决方案 »

  1.   

    select * from t1
    where patindex('%[a-z]%',c)=0 and patindex('%[0-9]%',c)=0
    and charindex('_',c)=0
      

  2.   

    --> 测试数据:[t1]
    if object_id('[t1]') is not null drop table [t1]
    create table [t1]([c] varchar(6))
    insert [t1]
    select 'aaa' union all
    select 'bcds' union all
    select 'a1' union all
    select '啊' union all
    select '^%' union all
    select 'ew1' union all
    select '344' union all
    select '__' union all
    select '213_21' union all
    select 'a_2' union all
    select 'd' union all
    select 'ddd' union all
    select '电风扇'select * from [t1]
    where patindex('%[a-z,0-9]%',c)=0 
    and charindex('_',c)=0----------------------

    ^%
    电风扇
      

  3.   

    ... WHERE PATINDEX('%[0-9a-z_]%',c)=0
      

  4.   


    select * from [t1]  WHERE PATINDEX('%[^0-9a-z_]%',c)=1
    /**
    c      
    ------ 

    ^%
    电风扇(所影响的行数为 3 行)
    **/
      

  5.   


    create table [t1]([c] varchar(6))
    insert [t1]
    select 'aaa' union all
    select 'bcds' union all
    select 'a1' union all
    select '啊' union all
    select '^%' union all
    select 'ew1' union all
    select '344' union all
    select '__' union all
    select '213_21' union all
    select 'a_2' union all
    select 'd' union all
    select 'ddd' union all
    select '电风扇'select * from [t1] where patindex('%[a-z,0-9,_]%',c)=0 drop table t1/*
    c      
    ------ 

    ^%
    电风扇(所影响的行数为 3 行)*/
      

  6.   

    select * from [t1] where patindex('%[a-z,0-9,_]%',c)=0  
    and datalength(c)<>len(c)*2
    -------
    ^%
      

  7.   

    select * from [t1] where patindex('%[a-z,0-9,_]%',c)=0  
    and datalength(c)=len(c)
      

  8.   

    select * from [t1] where patindex('%[a-z,0-9,_]%',c)=0  
    and datalength(c)=len(c)
      

  9.   

    非常感谢大家帮忙解决了这个问题,
    这个问题有个延伸的问题,在下面的帖子,希望大家接着帮忙解决,谢谢:http://topic.csdn.net/u/20100111/15/c2a124c5-bc5b-4626-86ce-c5b862cf5cff.html这个帖子就结贴了。
      

  10.   

    --TRY
    select * from [t1] WHERE PATINDEX('%[0-9a-z_吖-座]%',c)=0
      

  11.   

    这个就是我想要的,非常感谢, 请到下面这个帖子取分:http://topic.csdn.net/u/20100111/15/c2a124c5-bc5b-4626-86ce-c5b862cf5cff.html 
      

  12.   

    ...WHERE PATINDEX('%[0-9a-z_]%',a)=0 AND PATINDEX('%[^吖-座]%',a)=1