I've got a table as follows:
subNo subName parent
1 National 1
2 VA 1
3 MD 1
4 Fairfax 2
5 Alexandria 2
6 Baltimore 3
I'm trying to create a query/procedure that will take an input variable (subNo) and then return all child subNo's in a temp table or table variable. I can't seem to wrap my head around the recursiveness that I need, since this will be an n-deep hierarchy. For example, if I pass in a value of '2', I need a table returned containing the following:
2
4
5
Any help at all would be appreciated.
subNo subName parent
1 National 1
2 VA 1
3 MD 1
4 Fairfax 2
5 Alexandria 2
6 Baltimore 3
I'm trying to create a query/procedure that will take an input variable (subNo) and then return all child subNo's in a temp table or table variable. I can't seem to wrap my head around the recursiveness that I need, since this will be an n-deep hierarchy. For example, if I pass in a value of '2', I need a table returned containing the following:
2
4
5
Any help at all would be appreciated.