Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Created November 1, 2017 09:47
Show Gist options
  • Save tompazourek/dee81d950b1a56d0493016475c3cc821 to your computer and use it in GitHub Desktop.
Save tompazourek/dee81d950b1a56d0493016475c3cc821 to your computer and use it in GitHub Desktop.
Load items with all of their parent items as well.
WITH [NodesWithParents] AS
(
SELECT * FROM [Nodes] n WHERE n.[Id] IN (...)
UNION ALL
SELECT parent.* FROM [Nodes] parent
INNER JOIN [NodesWithParents] child ON child.[ParentNode_Id] = parent.[Id]
)
SELECT DISTINCT [Id] FROM [NodesWithParents]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment