I have a dataset that has parents and children that I am calling branches. Sample dataset:
Branch TreeId Name ParentId
Root 1 GRP A NULL
Root 2 SET A1 1
Child 6 SET A1B 2
Child 7 SET A1C 2
I then have a TreeId parameter that I need to pull from that level down to the children. This set will not go higher than a Root record where ParentId IS NULL. So what I am trying to do is let's say I pass in TreeId 1 in this case I would want the whole set back. Essentially any ParentId = Null can have additional roots under it. If I pass treeid = 2 I would want records 2,6 and 7. If I pass treeid 6 or 7 I would just want that record.
I would want to start with the NULL ParentId if it is null then work down based on the treeid passed in.