在 SSMS 上获取 TFS 工作项

Getting TFS work items on SSMS

我需要一些帮助来模拟 TFS 查询。 我尝试编写以下 SQL 查询来执行此操作,但我无法获得匹配的人口:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

IF OBJECT_ID('tempdb.dbo.#LastRecord') IS NOT NULL DROP TABLE #LastRecord 
SELECT System_Id
       , LastUpdatedDateTime = MAX(LastUpdatedDateTime) 
INTO #LastRecord
FROM [dimWorkItem]
GROUP BY System_Id 


SELECT distinct ID = w.System_Id
--Cannot find Department
       , Department = '?'
       , w.TeamProjectSK
       , RequestedByUser = w.Custom_RequestedBy
       , Title = w.System_Title  
       , [Priority] = w.Microsoft_VSTS_Common_Priority
       , Activity = w.Microsoft_VSTS_Common_Activity
       , da.AreaPath
       , [State] = w.System_State
       , Reason = w.System_Reason
       , ClosedDate = w.Microsoft_VSTS_Common_ClosedDate
       , ActivatedDate = Microsoft_VSTS_Common_ActivatedDate
       , DevHours = Custom_DevHours
       , CreatedDate = w.System_CreatedDate 
       , AssignedTo = dp.Name
       , [Week] = CASE WHEN (w.System_State = 'Active' OR Microsoft_VSTS_Common_ClosedDate >= dateadd(d,-7,CONVERT(Date,getdate(),1))) THEN 'Current' 
                       WHEN (w.System_State = 'Active' OR Microsoft_VSTS_Common_ClosedDate >= dateadd(d,-14,CONVERT(Date,getdate(),1)) AND Microsoft_VSTS_Common_ClosedDate < dateadd(d,-7,CONVERT(Date,getdate(),1))) THEN 'Last' 
                       ELSE 'Previous' END
       , TSRNumber = Custom_TSRNumber
FROM 

(Select * from (select *, rn = row_number() over(partition by w1.System_Id, w1.TeamProjectSK, w1.System_State order by w1.System_Rev desc)
      from dbo.DimWorkItem w1) d where rn = 1) w
JOIN #LastRecord l ON w.System_Id = l.System_Id AND w.LastUpdatedDateTime = l.LastUpdatedDateTime
LEFT OUTER JOIN dbo.DimArea da ON w.AreaSK = da.AreaSK
LEFT OUTER JOIN DimPerson dp ON w.System_AssignedTo__PersonSK = dp.PersonSK
WHERE System_WorkItemType = 'Task'
AND da.AreaPath like '\LOS\Reporting%'
AND w.Microsoft_VSTS_Common_Priority < 4 

此外,如果有人知道我在哪里可以找到部门字段,因为我不确定它是否是自定义字段。

SQL 服务器 2014:12.0

TFS: 12.0

Visual studio 专业 2015: 14.0

提前感谢您的建议!

我找到了解决方案,但仍然找不到“部门”字段:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

IF OBJECT_ID('tempdb.dbo.#LastRecord') IS NOT NULL DROP TABLE #LastRecord 

SELECT System_Id, LastChangedDate = MAX(System_ChangedDate) 
INTO #LastRecord
FROM [dimWorkItem]
GROUP BY System_Id 

DECLARE @FromDateWeek DATE 
DECLARE @FromDateTwoWeek DATE 
SET @FromDateWeek = dateadd(d,-7,CONVERT(Date,getdate(),1))
SET @FromDateTwoWeek = dateadd(d,-14,CONVERT(Date,getdate(),1))
--SELECT @FromDate

SELECT      ID = w.System_Id
    --Cannot find Department
          , Department = '?'
          , w.TeamProjectSK
          , RequestedByUser = w.Custom_RequestedBy
          , Title = w.System_Title  
          , [Priority] = w.Microsoft_VSTS_Common_Priority
          , Activity = w.Microsoft_VSTS_Common_Activity
          , da.AreaPath
          , [State] = w.System_State
          , Reason = w.System_Reason
          , ClosedDate = w.Microsoft_VSTS_Common_ClosedDate
          , ActivatedDate = Microsoft_VSTS_Common_ActivatedDate
          , DevHours = Custom_DevHours
          , CreatedDate = w.System_CreatedDate 
          , AssignedTo = dp.Name
          , [Week] = CASE WHEN  w.Microsoft_VSTS_Common_ClosedDate >= @FromDateWeek OR w.System_State = 'Active' THEN 'Current' 
                          WHEN (w.Microsoft_VSTS_Common_ClosedDate >= @FromDateTwoWeek AND w.Microsoft_VSTS_Common_ClosedDate < @FromDateWeek) 
                                OR w.Microsoft_VSTS_Common_ClosedDate < @FromDateWeek THEN 'Last' 
                          ELSE 'Previous' END
FROM [dimWorkItem] w 
JOIN #LastRecord l ON w.System_Id = l.System_Id AND w.System_ChangedDate = l.LastChangedDate
LEFT OUTER JOIN DimPerson dp ON w.System_AssignedTo__PersonSK = dp.PersonSK
LEFT OUTER JOIN dbo.DimArea da ON w.AreaSK = da.AreaSK

WHERE 
       da.AreaPath LIKE '\LOS\Reporting%'
       AND System_WorkItemType = 'Task'
       AND (Microsoft_VSTS_Common_ClosedDate >= @FromDateTwoWeek
              OR w.System_State = 'Active')
       AND ISNULL(Microsoft_VSTS_Common_Priority,0) < 4
       AND w.System_Reason <> 'Obsolete'