小弟遇到一个sql通配符问题,请大家指教。
   现在要查询一个字段中是否包含 a一个或多个空格b 字符串(以a开头,以b结尾,中间一个或多个空格),请问这要通配符如何写?
   select * from #a where name like 'a一个或多个空格符b'?
   

解决方案 »

  1.   

    select * from #a where name like 'a[ ]b'
      

  2.   


    select *
    from tb
    where left(col,1)='a' and right(col,1)='b' and replace(col,' ','')='ab'
      

  3.   

    declare @a table (col varchar(120))
    insert into @a select 'a    b'
    union all
    select 'a odfb'
    union all
    select 'a b'select *
    from @a
    where left(col,1)='a' and right(col,1)='b' and replace(col,' ','')='ab'
    测试完毕可以实现
      

  4.   

    where col like 'a%b' and replace(col,' ','')='ab'
      

  5.   

    不好意思,忘了补充了,a和b前后都有其他任意字母 like '%a一个或多个空格b%'
      

  6.   

    select * from tb where 字段名 like '%a%b%';
      

  7.   

    select * from tb 
    where Replace(col,' ','') like '%ab%' And col not like '%ab%'