Created
February 2, 2012 21:16
-
-
Save andy-uq/1725825 to your computer and use it in GitHub Desktop.
Returns the umbraco node tree and all descendants
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 @nodeId uniqueidentifier | |
SELECT @nodeId = 0 -- Put your node Id here | |
WITH NodeTree(ID, ParentID, [Level]) | |
AS | |
( | |
-- The immediate Node we're getting (which will be excluded in the final query) | |
SELECT a.ID, a.ParentID, 0 | |
FROM Node a | |
WHERE ID = @nodeId | |
UNION ALL | |
-- Recursively retrieve the children | |
SELECT a.ID, a.ParentID, [Level] + 1 | |
FROM Node a | |
INNER JOIN NodeTree p ON a.ParentID = p.ID | |
) | |
SELECT a.* | |
FROM [Node] a | |
INNER JOIN NodeTree tree ON a.ID = tree.ID | |
WHERE | |
a.ID <> @nodeId -- Delete the where clause to include the node within the results | |
ORDER BY tree.[Level], a.sortOrder, a.[text] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment