質問があります:
SELECT DTH.PointPerson AS Person
,PDT.[Name] AS Project
,(CASE WHEN TSK.Name IS NULL THEN NULL
WHEN SPT.[Name]+' - '+SPT.[Description] IS NULL THEN 'KanBan'
ELSE SPT.[Name]+' - '+SPT.[Description]
END) AS Sprint
,COALESCE(STY.[Number], NSS.IncidentNumber) AS Story
,TSK.[Name] AS Task
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 1 THEN DTH.[Hours] ELSE 0 END) AS Monday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 2 THEN DTH.[Hours] ELSE 0 END) AS Tuesday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 3 THEN DTH.[Hours] ELSE 0 END) AS Wednesday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 4 THEN DTH.[Hours] ELSE 0 END) AS Thursday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 5 THEN DTH.[Hours] ELSE 0 END) AS Friday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 6 THEN DTH.[Hours] ELSE 0 END) AS Saturday
,SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 7 THEN DTH.[Hours] ELSE 0 END) AS Sunday
,SUM(DTH.[Hours]) AS Total
FROM DailyTaskHours DTH
LEFT JOIN Task TSK ON DTH.TaskId = TSK.PK_Task
LEFT JOIN Story STY ON TSK.StoryId = STY.PK_Story
LEFT JOIN NonScrumStory NSS ON DTH.NonScrumStoryId = NSS.PK_NonScrumStory
LEFT JOIN Sprint SPT ON STY.SprintId = SPT.PK_Sprint
LEFT JOIN Product PDT ON STY.ProductId = PDT.PK_Product
GROUP BY DTH.PointPerson, PDT.[Name], SPT.[Name]
,SPT.[Description]
,STY.[Number]
,NSS.IncidentNumber
,TSK.[Name]
If: SUM(DTH.[Hours]) AS Total = 0 行を返さないようにしたい
アプローチは CASE WHEN を使用することだと思いますが、それがどこに行くのか正確に把握するのに苦労しています。