字段中保存的内容类似:“1 ¦2 ¦11 ¦12 ¦15 ¦25” 而外部获取的是:字段中其中的一个,如(其中的 1);要查找出所字段中有包含"1"的所有数据。要怎么写语句。
是asp.net,access数据库 

解决方案 »

  1.   

    sql
       select * from (表名) where 字段名 like '%1%'
      

  2.   

     like '%1%'  不可以吧, 如果我的字段中只有 11 那不是也符合条件。
      

  3.   

    select * from table1 where field like '%1%' not like '%11%'
      

  4.   

    晕,错了select * from table1 where field like '%1%' and field not like '%11%'
      

  5.   

    好像考虑的还不够细致
    这样select * from table1 where field like '%1|%' and field not like '%11|%'
      

  6.   

    你的这个问题...
    我错了
    头大了
    再改select * from table1 where field like '%|1|%' and field not like '%11|%'
      

  7.   

    啊,这样好像没考虑到1放到最头的情况,我诅咒csdn,不能让我修改
    再改select * from table1 where (field like '%|1|%' and field not like '%11|%') or (field like '1|%')没问题的吧??
      

  8.   

    哎,我惭愧啊,楼主的问题把我们都给框住了,以为很复杂呢,让我考虑偏了
    其实只要有分隔符就没问题
    create table a
    (
     b varchar(100)
    )
    insert a values('1|11|21|12|13|111|')
    insert a values('1111|11|21|12|13|111|1|123|23|')
    insert a values('123|11|21|12|13|111|13|')select * from a where b like '%|1|%' or b like '1|%'
      

  9.   

    还是不太明白 !  要不我说一下我要做的这功能: 比如管理员要给会员发信息, 同一条信息可发送给多个用户, 我的想法是把用户的id存在一个字段中,然后查询的时候去判断,会员的id要是在表中的话不查询出来,。没有的话就不显示是这样的。不知道是否清楚~~
      

  10.   


    你的意思我明白了
    你的表是这样的吧
    create table User
    (
     userid int not null,
     username varchar(50)

    insert user values(1,'xiaolin')
    insert user values(2,'xiaoming')
    insert user values(12,'xiaolinzi')
    insert user values(11,'xiaohua')
    insert user values(111,'xiaofeng')你这时候要给1,11发信息,你是不是想知道是不是在这个表里?
    这样
    select * from User where userid in('1','11')你是不是想这样做?