Created
November 19, 2021 12:31
-
-
Save kwestground/2a3df21e73c225eaa22f75b7a9c0bdda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH TreeRecursive AS | |
( | |
SELECT T0.ParentCode, T0.ChildCode, 0 [Level] FROM TreeTable T0 | |
WHERE ParentCode = 'ParentCode' | |
UNION ALL | |
SELECT TS.ChildCode, T0.ChildCode, TS.[Level] + 1 AS [Level] FROM TreeTable TS | |
INNER JOIN TreeTable T0 ON TS.ChildCode = T0.ParentCode | |
) | |
SELECT * FROM TreeRecursive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment