sql根据子部门id动态获取部门全路径

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

sql根据子部门id动态获取部门全路径

1.调用列子:select *From [dbo].[f_GetParentFullName](981769)

2.创建函数

create FUNCTION [dbo].[f_GetParentFullName](@id int)

  RETURNS @str TABLE(FullNam varchar(1000))

  AS

  begin

  declare @level int

  declare @FullName varchar(1000)

  set @level = 1

  declare @pid int

  select @pid = FPARENTID from T_BD_DEPARTMENT where FDEPTID = @id

  select @FullName=t1.FNAME from T_BD_DEPARTMENT t inner join T_BD_DEPARTMENT_L t1 on t.FDEPTID=t1.FDEPTID and t1.FLOCALEID=2052  where t.FDEPTID = @id

  select @pid = FPARENTID from T_BD_DEPARTMENT where FDEPTID = @id

  select @FullName=t1.FNAME+'/'+@FullName from T_BD_DEPARTMENT t inner join T_BD_DEPARTMENT_L t1 on t.FDEPTID=t1.FDEPTID and t1.FLOCALEID=2052  where t.FDEPTID =  @pid

  while @@rowcount > 0  

  begin

  select @pid = FPARENTID from T_BD_DEPARTMENT where FDEPTID = @pid

  select @FullName=t1.FNAME+'/'+@FullName from T_BD_DEPARTMENT t inner join T_BD_DEPARTMENT_L t1 on t.FDEPTID=t1.FDEPTID and t1.FLOCALEID=2052  where t.FDEPTID =  @pid

  end

  insert @str select @FullName

  return

  end

GO


sql根据子部门id动态获取部门全路径

1.调用列子:select *From [dbo].[f_GetParentFullName](981769)2.创建函数create FUNCTION [dbo].[f_GetParentFullName](@id int) ...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息