0

私はクエリに取り組んでいます:

SELECT D.PointPerson AS Person, R.[Name] AS Project, ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') AS Sprint, COALESCE(S.[Number], N.IncidentNumber) AS Story, T.[Name] AS Task,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 1 THEN D.[Hours] ELSE 0 END) AS Monday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 2 THEN D.[Hours] ELSE 0 END) AS Tuesday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 3 THEN D.[Hours] ELSE 0 END) AS Wednesday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 4 THEN D.[Hours] ELSE 0 END) AS Thursday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 5 THEN D.[Hours] ELSE 0 END) AS Friday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 6 THEN D.[Hours] ELSE 0 END) AS Saturday,
   sum(CASE WHEN DatePart(dw, D.ActivityDate) = 7 THEN D.[Hours] ELSE 0 END) AS Sunday,
   sum(D.[Hours]) AS Total
FROM DailyTaskHours D
LEFT JOIN Task T ON D.TaskId = T.PK_Task 
LEFT JOIN Story S ON T.StoryId = S.PK_Story 
LEFT JOIN NonScrumStory N ON D.NonScrumStoryId = N.PK_NonScrumStory 
LEFT JOIN Sprint P ON S.SprintId = P.PK_Sprint 
LEFT JOIN Product R ON S.ProductId = R.PK_Product
GROUP BY D.PointPerson, R.[Name], P.[Name], P.[Description], S.[Number], N.IncidentNumber, T.[Name]
ORDER BY CASE WHEN ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') = 'KanBan'
    THEN 1
    ELSE 0 END,
    Project ASC,
    Sprint ASC,
    Story ASC,
    Task ASC

名前と説明が NULL の場合、セルには 'KanBan' ISNULL(P.[Name]+' - '+P.[Description], 'KanBan') が入力されます。

これは私が望むように機能しています。ただし、3番目のセルがNULLの場合(T.[名前])、このセルもNULLにしたいと思います。

したがって、P.[Name]+' - '+P.[Description] (Sprint) が NULL の場合、T.[Name] が NULL でない限り KanBan を入力します。この場合、(Sprint) も NULL にしたいと思います。

どうすればこれを達成できますか?

4

1 に答える 1

3

これは、使用する正当な理由caseです:

select (case when T.Name is null then NULL
             when P.[Name]+' - '+P.[Description] is NULL then 'KanBan'
             else P.[Name]+' - '+P.[Description]
        end) AS Sprint
于 2013-09-18T14:38:40.780 に答える