Oh well that's a bit of shame -- they are great for this situation.However, Does this work for you?-- DataDECLARE @foo TABLE ( [name] VARCHAR(255) , [Id] INT , [managerId] INT , [status] VARCHAR(3) )INSERT @foo ([name], [Id], [managerId], [status]) SELECT 'TheBoss', 1, NULL, 'YES'UNION SELECT 'MD', 2, 1, 'No'UNION SELECT 'Line Manager', 3, 2, 'No'UNION SELECT 'Spod', 4, 3, 'No'UNION SELECT 'Sub Boss', 5, 1, 'YES'UNION SELECT 'Spod 2', 6, 5, 'No'-- QueryDECLARE @map TABLE ( [empId] INT , [managerId] INT , [path] VARCHAR(8000) , [found] BIT )DECLARE @rows INTDECLARE @maxIts INTDECLARE @its INTSET @rows = 1SET @maxIts = 1000SET @its = 0INSERT INTO @map ([empId], [managerId], [path], [found])SELECT f.[Id] , CASE f.[status] WHEN 'YES' THEN f.[Id] ELSE f.[managerID] END , f.[name] , CASE f.[status] WHEN 'YES' THEN 1 ELSE 0 ENDFROM @foo f-- Show beforeSELECT * FROM @mapWHILE ( @rows > 0 AND @its < @maxIts ) BEGIN UPDATE m SET [managerId] = CASE f.[status] WHEN 'YES' THEN f.[Id] ELSE f.[managerId] END , [path] = [path] + ' -> ' + f.[name] , [found] = CASE f.[status] WHEN 'YES' THEN 1 ELSE 0 END FROM @map m JOIN @foo f ON f.[ID] = m.[managerID] WHERE m.[found] = 0 SET @rows = @@ROWCOUNT SET @its = @its + 1END-- Show map after while loopSELECT * FROM @map-- ResultsSELECT f.[name] AS [Employee] , f2.[name] AS [Manager Who can Say YES] , m.[path] AS [Management Path]FROM @foo f JOIN @map m ON m.[empId] = f.[ID] LEFT JOIN @foo f2 ON f2.[Id] = m.[managerId]
Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION