SQL: Find nearest enabled parent in a hierarchy using T-SQL
I was recently answering a forum question about working with a hierarchy. The poster had a table of nodes but importantly, nodes could be disabled. If that happened, the children of the node would move up to their nearest parent that wasn’t disabled.
That is, if their parent was disabled and their grandparent was also disabled, then their great-grandparent would become their effective parent.
I provided the following code example, and I hope it helps someone.
2020-01-02




