3
我想要得到樹中特定節點的路徑。請看我的樹數據。獲取樹中節點的路徑
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 – 2013-04-30 09:06:40
嗨!看看這有助於http://msdn.microsoft.com/en-us/magazine/cc794278.aspx – Elmer 2013-04-30 10:41:38