有表t1
有个字段是townid
数值是这样的2|12|3|13|4|14|当我用select * from t1 where townid like '%2|%'查询时,不够精确
把含有12|22|这样的记录也查出来了。现请问,like 后面的条件应该如何写?

解决方案 »

  1.   

    charindex('|,2,|','|'+townid+'|')>0
      

  2.   

    charindex函数不行,位置不是固定的
      

  3.   

    select * from t1 where charindex( '|2|','|'+townid)>0
      

  4.   

    select * from t1 where charindex( '|2|','|'+townid)>0
      

  5.   

    和位置没关系,这个是判断是否存在select * from t1 where charindex('|' + '2' + '|','|' + townid) > 0
      

  6.   

    select * from t1 where '|'+townid+'|' like '%|2|%'