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


 

posted on 2009-09-28 08:54  poop  阅读(605)  评论(0编辑  收藏  举报