【发布时间】:2013-04-30 16:59:21
【问题描述】:
我想获取树中特定节点的路径。请查看我的树数据。
DECLARE @TT TABLE
(
Id int,
Name varchar(50),
Parent int
)
INSERT @TT
SELECT 1,' Great GrandFather Thomas Bishop', null UNION ALL
SELECT 2,'Grand Mom Elian Thomas Wilson' , 1 UNION ALL
SELECT 3, 'Dad James Wilson',2 UNION ALL
SELECT 4, 'Uncle Michael Wilson', 2 UNION ALL
SELECT 5, 'Aunt Nancy Manor', 2 UNION ALL
SELECT 6, 'Grand Uncle Michael Bishop', 1 UNION ALL
SELECT 7, 'Brother David James Wilson',3 UNION ALL
SELECT 8, 'Sister Michelle Clark', 3 UNION ALL
SELECT 9, 'Brother Robert James Wilson', 3 UNION ALL
SELECT 10, 'Me Steve James Wilson', 3
如何获取特定 id 的路径?例如对于 id = 5,结果是:
Great GrandFather Thomas Bishop -> Grand Mom Elian Thomas Wilson -> Aunt Nancy Manor
【问题讨论】:
-
当你输入 ID 5 时,你不需要 Grand Uncle Michael Bishop。
标签: sql-server tsql tree