答案 0 :(得分:0)
尝试使用CTE(About CTE):
DECLARE @SelectedNode INT = 103;
;WITH nodes AS
(
SELECT Node
, ParentNode
, GroupID
, Depth
FROM TableNodes WHERE Node = @SelectedNode
UNION ALL
SELECT tn.Node
, tn.ParentNode
, tn.GroupID
, tn.Depth FROM TableNode tn
INNER JOIN nodes n ON n.Node = tn.ParentNode
)
SELECT * FROM nodes;