在这个查询中,我计算前一周创建的工作订单并显示 wotype2 的计数。如果前一周的 wotype2 为零,我需要 wotype2 出现在我的结果中。关于如何解决这个问题的任何想法?
-- Retrieve Last Week's New Work Orders.
DECLARE @TodayDayOfWeek INT
DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime
--get number of a current day (1-Monday, 2-Tuesday... 7-Sunday)
SET @TodayDayOfWeek = datepart(dw, GetDate())
--get the last day of the previous week (last Sunday)
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
--get the first day of the previous week (the Monday before last)
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
SELECT wotype2 as WOType, COUNT(*) as NewWOsLastWeek
FROM tasks
WHERE ((OpenDATE BETWEEN
CONVERT(VARCHAR, @StartOfPrevWeek,7) AND
CONVERT(VARCHAR, @EndOfPrevWeek+1,7)) AND
(TYPE = 'Information Systems') AND
(RESPONS != 'ADMIN'))
group by wotype2
order by wotype2