Created
January 27, 2015 20:21
-
-
Save CodyEngel/fb4ad57db2d4e1535442 to your computer and use it in GitHub Desktop.
Get All Child Nodes Given A Parent
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
DECLARE @TopID_in int -- The top level we want to resolve children for | |
SELECT @TopID_in = -- ID of parent node | |
;WITH HierarchyCTE(ID, ParentID) AS | |
( | |
SELECT Id, ParentId | |
FROM Categories | |
WHERE Id = @TopID_in | |
UNION ALL | |
SELECT Categories.Id, Categories.ParentId | |
FROM Categories | |
INNER JOIN HierarchyCTE | |
ON Categories.ParentId = HierarchyCTE.Id | |
) | |
SELECT * | |
FROM HierarchyCTE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment