There\'s a tutorial:https://www.sqlservercentral.com/articles/hierarchies-on-steroids-1-convert-an-adjacency-list-to-nested-sets
USE TempDB; --===== C