I'd like to use a recursive function to calculate the depth of each Role as it is added. So a new field called depth will be added to the table tblOrganisationRoleOrgChart.
Given these two tables
tblOrganisationRoles
===========================
OrganisationRoleID int | OrganisationID int | Role varchar
1 1000 CEO
2 1000 CTO
3 1000 Tech
4 1000 General
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int | Depth
1 1
2 1
3 2
4 2
How would you write a recursive function to calculate the depth of a given Role as it was added? Any help appreciated
Given these two tables
tblOrganisationRoles
===========================
OrganisationRoleID int | OrganisationID int | Role varchar
1 1000 CEO
2 1000 CTO
3 1000 Tech
4 1000 General
tblOrganisationRoleOrgChart
===========================
OrganisationRoleID int | ReportsToID int | Depth
1 1
2 1
3 2
4 2
How would you write a recursive function to calculate the depth of a given Role as it was added? Any help appreciated