UFN_CORPORATESTRUCTURE_GETROOT
Returns the top level parent corporation in the corporate structure containing the given constituent.
Return
Return Type |
---|
uniqueidentifier |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CONSTITUENTID | uniqueidentifier | IN |
Definition
Copy
create function dbo.UFN_CORPORATESTRUCTURE_GETROOT(@CONSTITUENTID uniqueidentifier)
returns uniqueidentifier
as begin
declare @LOOPLIMIT integer
declare @LOOPCOUNTER integer
declare @ROOTID uniqueidentifier
set @LOOPLIMIT = 255
set @LOOPCOUNTER = 0
set @ROOTID = @CONSTITUENTID
while (select top 1 PARENTCORPID from dbo.ORGANIZATIONDATA where ID = @ROOTID) is not null and @LOOPCOUNTER < @LOOPLIMIT
begin
set @ROOTID = (select top 1 PARENTCORPID from dbo.ORGANIZATIONDATA where ID = @ROOTID)
set @LOOPCOUNTER = @LOOPCOUNTER + 1
end
return @ROOTID
end