我正在处理一个查询:
USE SCRUMAPI2
DECLARE @userParam VARCHAR(100)
,@startDateParam DATETIME
,@endDateParam DATETIME
,@orgTeamPK VARCHAR(100)
,@teamId VARCHAR(100)
,@productId VARCHAR(100)
,@search VARCHAR(200)
SET @userParam = 'David Tunnell (tunnelld)'
SET @startDateParam = '2013-10-21 00:00:00'
SET @endDateParam = '2013-10-27 23:59:59'
SET @orgTeamPK = '%'
SET @teamId = '%'
SET @productId = '%'
SET @search = '%%'
SELECT RowType AS RowType
,Person AS Person
,Project AS Project
,ProjectType AS ProjectType
,StoryNumber AS StoryNumber
,StoryTitle AS StoryTitle
,Effort AS Effort
,Task AS Task
,OriginalEstimateHours AS OriginalEstimateHours
,MondayHours AS Monday
,TuesdayHours AS Tuesday
,WednesdayHours AS Wednesday
,ThursdayHours AS Thursday
,FridayHours AS Friday
,SaturdayHours AS Saturday
,SundayHours AS Sunday
,TotalHours AS Total
FROM (
-- DATE DISPLAY
SELECT '1' AS RowType
,'' AS Person
,'' AS Project
,'Category' AS ProjectType
,'Incident #' AS StoryNumber
,'' AS StoryTitle
,'' AS Effort
,'' AS Task
,'' AS OriginalEstimateHours
,'' AS Category
,'' AS IncidentNumber
,'' AS ApplicationName
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 0, @startDateParam)) = 2 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 0, @startDateParam), 111) ELSE '' END) AS MondayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 1, @startDateParam)) = 3 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 1, @startDateParam), 111) ELSE '' END) AS TuesdayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 2, @startDateParam)) = 4 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 2, @startDateParam), 111) ELSE '' END) AS WednesdayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 3, @startDateParam)) = 5 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 3, @startDateParam), 111) ELSE '' END) AS ThursdayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 4, @startDateParam)) = 6 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 4, @startDateParam), 111) ELSE '' END) AS FridayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 5, @startDateParam)) = 7 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 5, @startDateParam), 111) ELSE '' END) AS SaturdayHours
,(CASE WHEN DATEDIFF(d, @startDateParam, @endDateParam) >= 7 THEN '' WHEN DATEDIFF(d, @startDateParam, @endDateParam) <= 5 THEN '' WHEN DATEPART(dw, DATEADD(DAY, 6, @startDateParam)) = 1 THEN CONVERT(VARCHAR(10), DATEADD(DAY, 6, @startDateParam), 111) ELSE '' END) AS SundayHours
,'' AS TotalHours
--
UNION ALL
--
-- GRAND TOTALS
--
SELECT '2' AS RowType
,'All Personnel' AS Person
,'' AS Project
,'' AS ProjectType
,'' AS StoryNumber
,'' AS StoryTitle
,'' AS Effort
,'Total:' AS Task
,'' AS OriginalEstimateHours
,'' AS Category
,'' AS IncidentNumber
,'' AS ApplicationName
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 2 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Monday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 3 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Tuesday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 4 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Wednesday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 5 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Thursday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 6 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Friday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 7 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Saturday
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 1 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS Sunday
,CAST(SUM(DTH.[Hours]) AS VARCHAR(20)) 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
LEFT JOIN ProductTeamUser PTU ON TSK.ProductTeamUserId = PTU.PK_ProductTeamUser
LEFT JOIN [User] USR ON PTU.UserId = USR.PK_User
LEFT JOIN OrganizationalTeam OLT ON USR.OrganizationalTeamId = OLT.PK_OrganizationalTeam
LEFT JOIN UserAuthorization UAN ON (
PDT.PK_Product = UAN.ProductId
AND USR.OrganizationalTeamId = UAN.OrganizationalTeamId
AND UAN.Deleted IS NULL
)
WHERE DTH.PointPerson LIKE @userParam
AND ActivityDate >= @startDateParam
AND ActivityDate <= @endDateParam
AND COALESCE(OLT.PK_OrganizationalTeam, '') LIKE @orgTeamPK
AND (
COALESCE(UAN.ProductId, '') LIKE @productId
OR COALESCE(UAN.OrganizationalTeamId, '') LIKE @teamId
)
AND (
(
STY.Number LIKE @search
OR STY.Number IS NULL
)
OR (
STY.Title LIKE @search
OR STY.Number IS NULL
)
OR (
TSK.NAME LIKE @search
OR STY.Number IS NULL
)
)
UNION ALL
--
-- Details by PERSON, PROJECT, SPRINT, STORY, TASK
--
SELECT '3' AS RowType
,DTH.PointPerson AS Person
,COALESCE(PDT.[Name], APP.AppName) AS Project
,(
CASE WHEN (
STY.KanBanProductId IS NOT NULL
AND STY.SprintId IS NULL
) THEN 'KanBan' WHEN (
STY.KanBanProductId IS NULL
AND STY.SprintId IS NOT NULL
) THEN 'Sprint' ELSE SCY.Catagory END
) AS ProjectType
,COALESCE(STY.[Number], NSS.IncidentNumber) AS StoryNumber
,COALESCE(STY.Title, NSS.[Description]) AS StoryTitle
,STY.Effort AS Effort
,COALESCE(TSK.[Name], '') AS Task
,TSK.OriginalEstimateHours AS OriginalEstimateHours
,SCY.Catagory AS Category
,NSS.IncidentNumber AS IncidentNumber
,APP.AppName AS ApplicationName
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 2 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS MondayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 3 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS TuesdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 4 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS WednesdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 5 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS ThursdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 6 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS FridayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 7 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS SaturdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 1 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS SundayHours
,CAST(SUM(DTH.[Hours]) AS VARCHAR(20)) AS TotalHours
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 SupportCatagory SCY ON NSS.CatagoryId = SCY.PK_SupportCatagory
LEFT JOIN [Application] APP ON NSS.ApplicationId = APP.PK_Application
LEFT JOIN Sprint SPT ON STY.SprintId = SPT.PK_Sprint
LEFT JOIN Product PDT ON STY.ProductId = PDT.PK_Product
LEFT JOIN ProductTeamUser PTU ON TSK.ProductTeamUserId = PTU.PK_ProductTeamUser
LEFT JOIN [User] USR ON PTU.UserId = USR.PK_User
LEFT JOIN OrganizationalTeam OLT ON USR.OrganizationalTeamId = OLT.PK_OrganizationalTeam
LEFT JOIN UserAuthorization UAN ON (
PDT.PK_Product = UAN.ProductId
AND USR.OrganizationalTeamId = UAN.OrganizationalTeamId
AND UAN.Deleted IS NULL
)
WHERE DTH.PointPerson LIKE @userParam
AND ActivityDate >= @startDateParam
AND ActivityDate <= @endDateParam
AND COALESCE(OLT.PK_OrganizationalTeam, '') LIKE @orgTeamPK
AND (
COALESCE(UAN.ProductId, '') LIKE @productId
OR COALESCE(UAN.OrganizationalTeamId, '') LIKE @teamId
)
AND (
(
STY.Number LIKE @search
OR STY.Number IS NULL
)
OR (
STY.Title LIKE @search
OR STY.Number IS NULL
)
OR (
TSK.NAME LIKE @search
OR STY.Number IS NULL
)
)
GROUP BY DTH.PointPerson
,PDT.[Name]
,SPT.[Name]
,SPT.[Description]
,STY.[Number]
,STY.Title
,TSK.[Name]
,SCY.Catagory
,NSS.IncidentNumber
,APP.AppName
,STY.KanBanProductId
,STY.SprintId
,NSS.[Description]
,TSK.OriginalEstimateHours
,STY.Effort
HAVING SUM(DTH.[Hours]) > 0
--
UNION ALL
--
-- Sub-TOTAL by PERSON
--
SELECT '4' AS RowType
,DTH.PointPerson AS Person
,'' AS Project
,'' AS ProjectType
,'' AS StoryNumber
,'' AS StoryTitle
,'' AS Effort
,'Subtotal:' AS Task
,'' AS OriginalEstimateHours
,'' AS Category
,'' AS IncidentNumber
,'' AS ApplicationName
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 2 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS MondayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 3 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS TuesdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 4 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS WednesdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 5 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS ThursdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 6 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS FridayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 7 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS SaturdayHours
,CAST(SUM(CASE WHEN DATEPART(dw, DTH.ActivityDate) = 1 THEN DTH.[Hours] ELSE 0 END) AS VARCHAR(20)) AS SundayHours
,CAST(SUM(DTH.[Hours]) AS VARCHAR(20)) AS TotalHours
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 SupportCatagory SCY ON NSS.CatagoryId = SCY.PK_SupportCatagory
LEFT JOIN [Application] APP ON NSS.ApplicationId = APP.PK_Application
LEFT JOIN Sprint SPT ON STY.SprintId = SPT.PK_Sprint
LEFT JOIN Product PDT ON STY.ProductId = PDT.PK_Product
LEFT JOIN ProductTeamUser PTU ON TSK.ProductTeamUserId = PTU.PK_ProductTeamUser
LEFT JOIN [User] USR ON PTU.UserId = USR.PK_User
LEFT JOIN OrganizationalTeam OLT ON USR.OrganizationalTeamId = OLT.PK_OrganizationalTeam
LEFT JOIN UserAuthorization UAN ON (
PDT.PK_Product = UAN.ProductId
AND USR.OrganizationalTeamId = UAN.OrganizationalTeamId
AND UAN.Deleted IS NULL
)
WHERE DTH.PointPerson LIKE @userParam
AND ActivityDate >= @startDateParam
AND ActivityDate <= @endDateParam
AND COALESCE(OLT.PK_OrganizationalTeam, '') LIKE @orgTeamPK
AND (
COALESCE(UAN.ProductId, '') LIKE @productId
OR COALESCE(UAN.OrganizationalTeamId, '') LIKE @teamId
)
AND (
(
STY.Number LIKE @search
OR STY.Number IS NULL
)
OR (
STY.Title LIKE @search
OR STY.Number IS NULL
)
OR (
TSK.NAME LIKE @search
OR STY.Number IS NULL
)
)
GROUP BY DTH.PointPerson
HAVING SUM(DTH.[Hours]) > 0
) AS My_View
ORDER BY Person
,RowType
,Project
,ProjectType
,StoryNumber
,StoryTitle
,Task
这就是返回的内容:
我将 Effort 和 OriginalEstimateHours 设置为空,但返回 0。如何使单元格为空白?