表1里其中一个字段deptid里有多个部门id,中间用逗号隔开,例如:01,03,09。
现在我要做查询,按照用户登录获得这个用户的部门id为09,现在的条件是,用户所在的部门必须在depid里存在,才能查询表1的数据。然后写sql查询语句。请教:怎么写?条件...

解决方案 »

  1.   


    string deptid="01,03,09";
    //開始構造where語句
    deptid=","+deptid+",";
    string sql=" where charindex(','+deptid+',','" + deptid + "')>0"其實也就是
    WHERE charindex(',09,',',01,03,09,')>0
      

  2.   

    select * from 表1 where exists( id in(select deptid from   表1));式下
      

  3.   


    string deptid="09";
    string sql=" where instr(','+deptid+',','" + deptid + "')>0"
      

  4.   

    ls的也不行,表本来就是用来存各字段的,为何不每个ID用一个字段呢,你这样是很麻烦的,
    用like "___"+deptid+"*" 吧(前面有几个字符就加几个_)
      

  5.   


    oracle中用这个函数instr 用法差不多...
      

  6.   

    select * from Department where  deptid like '%09%'
      

  7.   

    select * from 表1 where exists (select 'x' from 表1 where deptid like '%,09,%')
      

  8.   

    select * from 表1 where exists (select 'x' from 表1 where deptid   like '%,09,%')
    试试
      

  9.   

    搞定,谢谢,不过大家的方法都没用,不过有一点是用的like。。给分。