USE [tb1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[f_getorg](@orgid varchar(32))
RETURNS varchar(32)
AS
BEGIN
--type 1:职能部门 2:项目部 3:分子公司 4:专业公司 5:总公司
DECLARE @id varchar(32)
DECLARE @parentid varchar(32)
DECLARE @type varchar(1)
select @id = id,@parentid=parentid,@type=type from t_hr_org where id=@orgid
while (@type<>3 and @type<>2 and @type<>4 and @type<>5 and @parentid is not null)
begin
select @id = id,@parentid=parentid,@type=type from t_hr_org where id=@parentid
end
RETURN @id
END
GO