I have two tables containing employee names (TableB) and Employee hierarchy( TableA) (manager_id from TableA can be employee_id in the same table ).
TableA
UniqueId Employee_ID Manager_ID
1 101 102
2 102 103
3 103 104
4 105 106
5 106 null
TableB
Employee_ID Employee_Name
101 First
102 Second
103 Third
104 Fourth
105 Fifth
106 Sixth
and I need output as below :
Employee_ID Employee_Name Transferred
101 First True
102 Second True
103 Third True
105 Fifth False
106 Sixth False
The Transferred column for each employee is calculated as =
isTransferred(Employee_ID)
{
If(Manager_ID is null) return false;
If(Manager_ID is present as employee_id in table A)
{
return isTransferred(manager_ID)
}
else
{
return true;
}
}
Is there any way to get the result in one select statement?