请教大家:            select * from people where depano like 'B01%' or depano like 'D011'
       
       部门编号是动态的,有的人可能是多个部门,或有的人只有一个            现在就是做一个导入excel功能,卡部门权限,每个人只能导入规定权限的部门的人员资料     
            我建的权限表,部门是用逗号隔开的那种
         
            暂时想到用like模糊查询方法。不清楚到底怎么写。
             
             先谢谢了。                        

解决方案 »

  1.   

     where charindex(depano+','+权限表部门列+',')>0
      

  2.   


    declare @table table (id int,col varchar(1))
    insert into @table
    select 101,'a' union all
    select 201,'b' union all
    select 301,'c' union all
    select 409,'d'declare @userid varchar(2000),
    @sqlstr varchar(4000)
    set @userid='201,102,301,104,199'--部门idSELECT * FROM @table 
    WHERE CHARINDEX(','+CAST(id AS VARCHAR(4))+',',','+@userid+',')>0
    /*
    id          col
    ----------- ----
    201         b
    301         c
    */
      

  3.   


    select * from people where depano not like 'B01%' or not depano like 'D011%'先从权限表中查询出汇入Excel人的部门权限在汇入Excel人员资料中排除权限表中部门NO