我有一个问题跟踪数据库。我需要能够提供一个日期范围内每天打开和关闭的所有问题的报告。
我已经能够一次生成一列的结果......全部打开或全部关闭。我真的很想一次性完成所有工作,而不是在一份报告中分两部分提供结果。
有问题的列是 dteOpen (datetime)、dteClosed(datetime)。
这是我返回所有打开的东西。
Declare @dt1 datetime = '1/1/1900',
Declare @dt2 datetime = '1/1/1900',
Declare @tT int = 0IF OBJECT_ID('tempdb..#TempDate') IS NoT NULL
DROP TABLE #TempDate
;WITH ctedaterange
AS (SELECT [rn]=Row_number()
OVER(
ORDER BY (SELECT NULL))
FROM sys.objects a
CROSS JOIN sys.objects b
CROSS JOIN sys.objects c
CROSS JOIN sys.objects d)
SELECT CAST(Dateadd(dd, rn, @dt1) AS DATE) As DateRange
into #TempDate
FROM ctedaterange
WHERE [rn] <= Datediff(dd, @dt1, @dt2)
Select td.DateRange,Count(ID)as countNumber
from #TempDate td
LEFT outer JOIN tblProblemslist pl
ON CAST(pl.dtmOpen AS DATE) = td.DateRange
AND dtmOpen between @dt1 and @dt2
AND ticketType = @tT
Group by td.DateRange
Order by td.DateRange