我有一个表叫公司 比如就两个字段 一个是公司ID 一个叫名字集合(names)names里存的是以点号隔开的名字id的集合 比如:
id            names1            12,23,342            3,55,134            7,87,4,66,11
如果我想查出来名字id是23的人他在哪个公司  该怎么写这个SQL语句?

解决方案 »

  1.   

    where 条件用charindex(',23,',','+names+',')<>-1 
      

  2.   

    "select * from tb where charindex(',23,' , ','+names+',')>0""select * from tb where charindex(',"+txtName.Text+",' , ','+names+',')>0"
      

  3.   

    where charindex(','+names+',',','+23+',')>0
      

  4.   

    where charindex(','+23+',',','+names+',')>0
      

  5.   

    str="23"
    sql="select id from tb where ','+names+',' like '%,"+str+",%'"