UFN_ORGANIZATIONHIERARCHY_POSITIONISPARENT
Returns the first parent record that the user has rights to.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@POSITIONID | uniqueidentifier | IN | |
@PARENTPOSITIONID | uniqueidentifier | IN |
Definition
Copy
--This function uses a while loop to determine if one position is under another.
--I am using this instead of recursion for operations where I need to affect all levels child nodes
--recursion would limit us to 32 levels
CREATE function dbo.UFN_ORGANIZATIONHIERARCHY_POSITIONISPARENT
(
@POSITIONID uniqueidentifier,
@PARENTPOSITIONID uniqueidentifier
)
returns bit
as
begin
declare @ITERATION integer;
set @ITERATION = 1;
if @PARENTPOSITIONID = @POSITIONID or @POSITIONID is null
return 0;
--Using while loop instead of recursion
--protect against runaway process
while @ITERATION < 100
begin
select @POSITIONID = PARENTID
from dbo.ORGANIZATIONHIERARCHY
where ORGANIZATIONHIERARCHY.ID = @POSITIONID
--not related
if @POSITIONID is null
return 0;
--If we the use has rights to the parent of there is no parent
if @PARENTPOSITIONID = @POSITIONID
return 1;
set @ITERATION = @ITERATION + 1
end
return 0;
end