How can I generate a hierarchy path in SQL that leads to a given node?
问题 In my MS SQL 2008 R2 database I have this table: TABLE [Hierarchy] [ParentCategoryId] [uniqueidentifier] NULL, [ChildCategoryId] [uniqueidentifier] NOT NULL I need to write a query that will generate all paths that lead to a given Node. Lets say it I have the following tree: A -B --C -D --C Which would be stored as: NULL | A A | B A | D B | C D | C When asking for the Paths for C, I would like to get back two paths (written more or less like this): A > B > C, A > D > C 回答1: Here is my