我在 SQL Server 2008 中工作。我正在编写一个每周聚合数据的存储过程。
聚合代码是
ALTER PROCEDURE [dbo].[ups_URLBatchStats]
(@startDate datetime, @endDate datetime,@source varchar(8))
AS BEGIN
SELECT
DATEADD(wk, DATEDIFF(wk, 0, ScheduleDate), 6) AS [Week Commencing],
SUM(Unresolved) AS Unresolved,
SUM(Resolved) AS Resolved,
SUM(TurkSpend) AS TurkSpend
FROM
dbo.V_URLBatchStats
WHERE
ScheduleDate BETWEEN @startDate AND @endDate
AND Source = ISNULL(@source, Source)
GROUP BY
DATEADD(wk, DATEDIFF(wk, 0, ScheduleDate), 6)
ORDER BY
DATEADD(wk, DATEDIFF(wk, 0, ScheduleDate), 6)
END
显示它给了我正确的结果,但是如果任何一周都没有数据,我必须在列中显示它的值为“0”。
那么我该如何处理这些跳过的每周行呢?
提前致谢。