id     a
1     2|3
2     1|2
3     12|1
如何查询A字段中包含2的记录。而12这样不算。

解决方案 »

  1.   

    select * 
    from tb
    where charindex('|2|','|'+a+'|')>0
      

  2.   


    declare @val varchar(10)
    set @val='2'
    select * from tb where charindex('|'+@val+'|','|'+a+'|')>0
      

  3.   


    --或者:select * from tb where '|'+a+'|' like '%|2|%'
      

  4.   

    忘记说了。数据库是ACCESS的。请问有什么方法吗?
      

  5.   

    id     a 
    1     2 ¦3 
    2     1 ¦2 
    3     12 ¦1 
    如何查询A字段中包含2的记录。而12这样不算。-------------------------sql serverselect * from tb where charindex(',2,' , ',' + a + ',') > 0
      

  6.   

    access 应该是用
    SEARCH(find_text,within_text,start_num)吧 ,
    好像是
    select * 
    from tb 
    where SEARCH( '|' + a + '|','|2|',1) > 0