this should work
drop table #hirNode
go
Create Table #hirNode(
hirNode Int
,hirNodeParent int
,Title varchar(100)
)
Insert into #hirNode
values (1,NULL,'Start')
,(2,1,'Second')
,(3,2,'Third')
,(4,NULL,'Start2')
,(5,4,'Second2');
WITH BuildPath(hirNode,hirNodeParent, NodeLevel, NodePath)
AS (SELECT hirNode,
hirNodeParent,
1,
CONVERT(varchar(255), '\\'+Title)
FROM #hirNode
WHERE hirNodeParent IS NULL --Start at the Top
UNION ALL
SELECT
h.hirNode,
h.hirNodeParent,
NodeLevel + 1,
CONVERT (varchar(255), RTRIM(NodePath) + '\' + Title)
FROM #hirNode AS h
JOIN BuildPath AS p ON h.hirNodeParent = p.hirNode
)
Update
hr
Set
FullPath=bp.NodePath
From
hirNodes hr
JOIN BuildPath bp on hr.hirNode=bp.hirNode
but you should check it
_________________________________________________________________________
SSC Guide to Posting and Best Practices