表ta存储的是组织机构信息,也可以当做权限控制表 create table ta(id int,parentID int ,code varchar(50)) insert ta values(1,0,'00') insert ta values(2,1,'0001') insert ta values(3,2,'000001') 假设tb存储的是信息select * from tb a join ta b on 连接条件 where b.code like(select code from ta where id = @id)+'%'
階級权限过滤数據,給個思路:建立個權限表與資料表關聯,用不同的ID(11029,11021...代表集團、單位、部門設計等) select * from wko_epmc where wko_planner in (11029) 依次類推,寫權限代碼(用權限代碼控制打開程序瀏覽不民的資料內容等
declare @table table (序号 int,部门 varchar(20),部门编号 varchar(20)) insert into @table select 1,'总部','aaa' union all select 2,'第一分公司','aaa111' union all select 3,'第二分公司','aaa222' union all select 4,'第三分公司','aaa333' union all select 5,'办事处1','aaa111001' union all select 6,'办事处1','aaa222001' union all select 7,'办事处1','aaa333001' union all select 8,'办事处2','aaa111002' union all select 9,'办事处2','aaa222002' union all select 10,'办事处2','aaa333002'union all select 11,'办事处3','aaa111003' select * from @table /* 序号 部门 部门编号 ----------- -------------------- -------------------- 1 总部 aaa 2 第一分公司 aaa111 3 第二分公司 aaa222 4 第三分公司 aaa333 5 办事处1 aaa111001 6 办事处1 aaa222001 7 办事处1 aaa333001 8 办事处2 aaa111002 9 办事处2 aaa222002 10 办事处2 aaa333002 11 办事处3 aaa111003(11 row(s) affected) */--如果是某部门登陆,按其部门编号进行模糊查询就行 declare @t varchar(20) set @t='第一分公司' select @t=部门编号 from @table where 部门=@t select * from @table where 部门编号 like @t +'%' /* 序号 部门 部门编号 ----------- -------------------- -------------------- 2 第一分公司 aaa111 5 办事处1 aaa111001 8 办事处2 aaa111002 11 办事处3 aaa111003(4 row(s) affected) */
1 XX公司 0
2 XX公司YY子公司 1
3 某某部门 2
4 XX公司ZZ子公司 1
表ta存储的是组织机构信息,也可以当做权限控制表
create table ta(id int,parentID int ,code varchar(50))
insert ta values(1,0,'00')
insert ta values(2,1,'0001')
insert ta values(3,2,'000001')
假设tb存储的是信息select * from tb a join ta b on 连接条件
where b.code like(select code from ta where id = @id)+'%'
依次類推,寫權限代碼(用權限代碼控制打開程序瀏覽不民的資料內容等
declare @table table (序号 int,部门 varchar(20),部门编号 varchar(20))
insert into @table
select 1,'总部','aaa' union all
select 2,'第一分公司','aaa111' union all
select 3,'第二分公司','aaa222' union all
select 4,'第三分公司','aaa333' union all
select 5,'办事处1','aaa111001' union all
select 6,'办事处1','aaa222001' union all
select 7,'办事处1','aaa333001' union all
select 8,'办事处2','aaa111002' union all
select 9,'办事处2','aaa222002' union all
select 10,'办事处2','aaa333002'union all
select 11,'办事处3','aaa111003'
select * from @table
/*
序号 部门 部门编号
----------- -------------------- --------------------
1 总部 aaa
2 第一分公司 aaa111
3 第二分公司 aaa222
4 第三分公司 aaa333
5 办事处1 aaa111001
6 办事处1 aaa222001
7 办事处1 aaa333001
8 办事处2 aaa111002
9 办事处2 aaa222002
10 办事处2 aaa333002
11 办事处3 aaa111003(11 row(s) affected)
*/--如果是某部门登陆,按其部门编号进行模糊查询就行
declare @t varchar(20)
set @t='第一分公司'
select @t=部门编号 from @table where 部门=@t
select * from @table where 部门编号 like @t +'%'
/*
序号 部门 部门编号
----------- -------------------- --------------------
2 第一分公司 aaa111
5 办事处1 aaa111001
8 办事处2 aaa111002
11 办事处3 aaa111003(4 row(s) affected)
*/