Ad Code

Responsive Advertisement

Hierarchical Query to Return All Children and Parent

--========Get all ancestor
;WITH cte AS ( SELECT dbTable.* FROM dbTable WHERE id = 100000200 UNION ALL SELECT dbTable.* FROM dbTable INNER JOIN cte ON cte.ParentID = dbTable.id ) SELECT * FROM cte
--========Get all successor
;WITH cte AS ( SELECT dbTable.* FROM dbTable WHERE id = 100000200 UNION ALL SELECT dbTable.* FROM dbTable INNER JOIN cte ON dbTable.ParentID = cte.id ) SELECT * FROM cte

Post a Comment

1 Comments

Close Menu