myfield like 'test'我想让test的前面是,或空后面也是只能是,或空
这个通配符应该怎么写,
自己试了下
like '[\,NULL]test[\,NULL]'
都不对

解决方案 »

  1.   

    set nocount on
    declare @t table(col varchar(10))
    insert @t select 'test'
    insert @t select ',test'
    insert @t select 'test,'
    insert @t select ',test,'
    insert @t select 'aatest'
    insert @t select 'testaa'
    insert @t select 'aaatestaa'select *
    from @t 
    where charindex(',test,',','+col+',') > 0/*
    col        
    ---------- 
    test
    ,test
    test,
    ,test,*/set nocount off
      

  2.   


    --这样?
    declare @t table(name varchar(50))
    insert into @t select ',test,asdf'
    insert into @t select ',test asdf'
    insert into @t select ',test3,asdf'
    insert into @t select ' test,asdf'
    insert into @t select 'stest,asdf'
    insert into @t select ',stest,asdf'select * from @t 
    where patindex('%[, ]'+'test'+'[, ]%',name)>0
      

  3.   

    楼主是要NULL  ,不是空格
      

  4.   

    严格应该是  '' 而非NULL
      

  5.   


    哪有字符里面包含字符,又包含NULL的?
    说的空格是指' '吧
      

  6.   

    如果记录中有
    ,,test
    test,,
    ,,,test,,,,,,
    之类的话,前后辍加','再charindex也会取错。