To get the "---" prefix you could just doSELECT REPLICATE('-', LEVEL)Note that your proposed PARENT / CHILD table doesn't tell you the sequence of the children (maybe you are happy to use the PK of the original table as a tie-break?)I'm not quite sure how your current LEVEL helps - I don't see how you know that Code=120000 (ACCOUNT5) is a child of 113000 (ACCOUNT4) rather than 112000 (ACCOUNT3) or 119000 (ACCOUNT6) as all three are the same level, and thus potential parents - in the absence of some extra information.Given knowledge of what the PARENT and immediately elder SIBBLING are, and assuming no more than 999 LEVELS and 999 SIBBLINGS for any given PARENT, the following code will construct LEVEL [i.e. Number of ancestors that exist back to the Root], SEQUENCE [i.e. Eldest to Youngest sibbling sequence] and a PATH [concatentation of all IDs of Parents/GrandParents etc.]Note that duplicate SIBBLING references would yeild indeterminate SIBBLING SEQUENCE ...-- Note that if Sibbling pointers are NOT unique the sequence generated is indeterminateDROP TABLE #MyTempTableGOCREATE TABLE #MyTempTable( [T_MyID] int, [T_MyParent] int, [T_MySibbling] int, [T_MyLevel] int, [T_MySequence] int, [T_MyPath] varchar(7000))-- Select all relevant original data into temporary tableINSERT INTO #MyTempTableSELECT [T_MyID] = MyID, [T_MyParent] = MyParent, [T_MySibbling] = MySibbling, [T_MyLevel] = NULL, [T_MySequence] = NULL, [T_MyPath] = NULLFROM dbo.MyTableDECLARE @intLoop int, @intRowCount int-- Set LEVEL and SEQUENCE for Root NodeUPDATE USET [T_MyLevel] = 0, [T_MySequence] = 0, [T_MyPath] = '000000' -- Max is 999 Levels and 999 Siblings, thus 6-digitsFROM #MyTempTable UWHERE T_MyParent IS NULL AND T_MySibbling IS NULL-- Set SEQUENCE on all Eldest SiblingsUPDATE USET [T_MySequence] = 0FROM #MyTempTable UWHERE T_MySibbling IS NULLSELECT @intLoop = 0, @intRowCount = 1 -- Force to run at least once-- Set SEQUENCE on all rowsWHILE (@intRowCount >= 1)BEGIN IF @intLoop >= 999 RAISERROR ('Maximum Sibbling Sequence exceeded', 16, 1) -- Set all next-younger sibblings to the next-higher sequence UPDATE C SET [T_MySequence] = @intLoop + 1 FROM #MyTempTable C JOIN #MyTempTable P ON P.T_MyID = C.T_MySibbling WHERE C.T_MySequence IS NULL -- Not-yet-done children ... AND P.T_MySequence IS NOT NULL -- ... of already-done parents AND P.T_MySequence = @intLoop SELECT @intRowCount = @@ROWCOUNT-- SELECT [Level] = @intLoop, [Count] = @intRowCount -- Debug SELECT @intLoop = @intLoop + 1 -- Proceed to next levelENDSELECT @intLoop = 0, @intRowCount = 1 -- Force to run at least once-- Set LEVEL on all rowsWHILE (@intRowCount >= 1)BEGIN IF @intLoop >= 999 RAISERROR ('Maximum Child Level exceeded', 16, 1) -- Set all children to the next-higher level UPDATE C SET T_MyLevel = @intLoop + 1, T_MyPath = P.T_MyPath + '/' + RIGHT('000'+CONVERT(varchar(20), @intLoop+1), 3) + RIGHT('000'+CONVERT(varchar(20), C.T_MySequence), 3) FROM #MyTempTable C JOIN #MyTempTable P ON P.T_MyID = C.T_MyParent WHERE C.T_MyLevel IS NULL -- Not-yet-done children ... AND P.T_MyLevel IS NOT NULL -- ... of already-done parents AND P.T_MyLevel = @intLoop SELECT @intRowCount = @@ROWCOUNT-- SELECT [Level] = @intLoop, [Count] = @intRowCount -- Debug SELECT @intLoop = @intLoop + 1 -- Proceed to next levelEND-- Set the Level, Sequence and Path on the original tableUPDATE USET MyLevel = T.T_MyLevel, MySequence = T.T_MySequence, MyPath = T.T_MyPathFROM #MyTempTable T JOIN dbo.MyTable U ON U.MyID = T.T_MyIDThis approach is fine if you only want to add new records at the END of a limb. If you want to INSERT in the middle of a limb, or if you want to be able to MOVE nodes to different parts of the tree, then you need something that either 1) renumbers the tree every time :-( or 2) leaves gaps for insertions and renumbers parts of the tree when they are full.Kristen