Skip to content

Instantly share code, notes, and snippets.

@appakz
Created June 28, 2012 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appakz/3013243 to your computer and use it in GitHub Desktop.
Save appakz/3013243 to your computer and use it in GitHub Desktop.
SQL Server HierarchyID.IsDescendantOf() behavior
declare @rootId HierarchyId = HierarchyId::Parse('/1/')
declare @descendantId HierarchyId = HierarchyId::Parse('/1/1/')
--make sense:
select @descendantId.IsDescendantOf(@rootId) --returns 1
select @rootId.IsDescendantOf(@descendantId) --returns 0
--not so much sense:
select @descendantId.IsDescendantOf(@descendantId) --returns 1
select @rootId.IsDescendantOf(@rootId) --returns 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment