create procedure sp_test(@uid varchar(6))
as
begin
select aid into #t from 员工表 where uid = @uid
if exists(select 1 from 部门表 A,#t B where A.aparentid = B.aid and not exsits(select 1 from #t where aid = A.aid))
insert into
#t
select
A.aid
from
部门表 A,
#t B
where
A.aparentid = B.aid
and
not exsits(select 1 from #t where aid = A.aid)
select a.uid from 员工表 A ,#t B where A.aid = B.aid
end
as
begin
select aid into #t from 员工表 where uid = @uid
if exists(select 1 from 部门表 A,#t B where A.aparentid = B.aid and not exsits(select 1 from #t where aid = A.aid))
insert into
#t
select
A.aid
from
部门表 A,
#t B
where
A.aparentid = B.aid
and
not exsits(select 1 from #t where aid = A.aid)
select a.uid from 员工表 A ,#t B where A.aid = B.aid
end
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货