I have an OrganizationStructure table like this:
OrganisationID INT
ParentOrganisationID INT
OrganisationName VARCHAR(64)
1 | 0 | Company
2 | 1 | IT DIVISION
3 | 2 | IT SYSTEM BUSINESS UNIT
4 | 1 | MARKETING DIVISION
5 | 4 | DONATION BUSINESS UNIT
I want to get a query that, if passing the let say application, OrganisatinID = 1means that it will be cyclically (looking at the parent / child) to the end of this table and grap all possible Returned OrganisatioIDs = (1, 2, 3, 4, 5).
Other if transferred OrganisationID = 2and then returnedOrganisationID = (2, 3)
Other if skipped OrganisationID = 3and then returnedOrganisationID = 3
Any ideas to do this without a cursor?
thanks
source
share