set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

--ALTER
create function [dbo].[autid](@userid int)
 returns int
 as
begin
 declare @deptmanageid int
 declare @i int
 declare @pareid int

 select @i=fdeptid,@pareid=fdept_manageid from fp_comp_dept
 where fdeptid in(select bdeptid from fp_user where userid=@userid)
 --select fatherdeptid from fp_comp_dept where fdept_manageid
 --in(select fdept_manageid from fp_comp_dept where fdeptid in(select deptid from fp_user where userid=@userid)))
-------判断上级部门的主管是否为CEO或者副总
 if @i<>2 and @i<>4
 begin
  select @deptmanageid=fdept_manageid from fp_comp_dept where fdeptid in(
  select fatherdeptid from fp_comp_dept where fdept_manageid=@pareid)
 end
 else
 begin
  select @deptmanageid=fdept_manageid from fp_comp_dept where fdeptid in(
   select fatherdeptid from  fp_comp_dept where fdeptid in
  (select bdeptid from fp_user where userid=@userid))
 end
return @deptmanageid
end


 

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-09-29
  • 2021-05-26
  • 2021-06-18
  • 2021-06-17
相关资源
相似解决方案