Сначала проверьте это в тестовой среде .
Также я изменил запрос из стандартного отчета TFS с рабочей иерархией.Работает только с одной коллекцией.Если у вас есть несколько коллекций, они могут быть обновлены:
DECLARE @ParentWorkItemLinkTypeSK int;
SET @ParentWorkItemLinkTypeSK = (SELECT [WorkItemLinkTypeSK] FROM [DimWorkItemLinkType] WHERE [LinkID] < 0 AND [ReferenceName] = 'System.LinkTypes.Hierarchy');
DECLARE @ChildWorkItemLinkTypeSK int;
SET @ChildWorkItemLinkTypeSK = (SELECT [WorkItemLinkTypeSK] FROM [DimWorkItemLinkType] WHERE [LinkID] > 0 AND [ReferenceName] = 'System.LinkTypes.Hierarchy');
DECLARE @ProjectName nvarchar(256);
SET @ProjectName = 'DEV'; -- set the team project name
DECLARE @RootNodeIDs TABLE (ID int);
INSERT @RootNodeIDs
-- This is selecting all deliverable workitems
SELECT cwi.[System_Id] AS ID FROM [CurrentWorkItemView] cwi
WHERE cwi.[System_WorkItemType] IN ('Bug', 'Product Backlog Item', 'Requirement')
AND cwi.[ProjectNodeName] = @ProjectName
EXCEPT
-- This is selecting all workitems that have a parent and have not been deleted
SELECT lh.SourceWorkItemID AS ID FROM FactWorkItemLinkHistory lh
JOIN [CurrentWorkItemView] cwi ON cwi.System_Id = lh.TargetWorkItemID
WHERE lh.WorkItemLinkTypeSK = @ParentWorkItemLinkTypeSK
AND cwi.System_WorkItemType IN ('Bug', 'Product Backlog Item', 'Requirement')
AND lh.RemovedDate = CONVERT(DATETIME, '9999', 126)
DECLARE @Hierarchy TABLE (ID int, ParentID int, [Level] int, [Path] nvarchar(4000));
WITH
Hierarchy (ID, ParentID, [Level], [Path]) AS
(
SELECT ID, NULL as ParentID, 0 as [Level], CAST('/' + STR(ID) AS nvarchar(256)) as [Path]
FROM @RootNodeIDs rootId
UNION ALL
SELECT flh.TargetWorkItemID as ID, Parent.ID, parent.Level + 1 as [Level],
CAST(parent.Path + '/' + STR(flh.TargetWorkItemID) AS nvarchar(256)) as [Path]
FROM Hierarchy parent
JOIN FactWorkItemLinkHistory flh
ON flh.WorkItemLinkTypeSK = @ChildWorkItemLinkTypeSK
AND flh.SourceWorkItemID = parent.ID
AND flh.RemovedDate = CONVERT(DATETIME, '9999', 126)
JOIN [CurrentWorkItemView] wi ON flh.TargetWorkItemID = wi.[System_ID]
WHERE parent.Path NOT LIKE CAST('%' + STR(flh.TargetWorkItemID) + '%' AS nvarchar(20)) AND parent.Level < 20
)
INSERT @Hierarchy SELECT * FROM Hierarchy;
-- Hierarchy now contains all the Tasks and their ancestors that we're interested
SELECT hierarchy.ID, ParentID, [Level], [Path], [ProjectNodeName] as Project, [System_State] as [State],
[Microsoft_VSTS_Scheduling_RemainingWork] Remaining,
[Microsoft_VSTS_Scheduling_CompletedWork] Completed,
([Microsoft_VSTS_Scheduling_RemainingWork] + [Microsoft_VSTS_Scheduling_CompletedWork]) Total,
[System_WorkItemType] WIT,
[System_Title] Title,
[AreaPath] AreaPath,
[IterationPath] IterationPath
FROM @Hierarchy hierarchy
INNER JOIN [CurrentWorkItemView] ON hierarchy.ID = [System_ID]
ORDER BY [System_Id]
Результат: