Hello,
Im using below query to get Count results for today.
Declare @Hours Table (Hour int);
Declare @i as int;
Set @i = 0
While @i < 23
Begin
Insert into @Hours
Values(@i);
Set @i = @i + 1;
End;
Select
[Hour of Day],
Count(SERL_NBR) AS [Serial]
From
(
SELECT DATEPART(HOUR, PART_TST_TS) AS [Hour of Day] , SERL_NBR
FROM JCIMWhitby.dbo.REPL_TRH REPL_TRH
WHERE (REPL_TRH.PART_LOT_DSC Like 'FRT Audit%') AND DATEDIFF(day, PART_TST_TS, GETDATE()) = 0
Union ALL
SELECT Hour, NULL
From @Hours
) as [DATA]
GROUP BY [Hour of Day]
ORDER BY [Hour of Day]
How do I query count like this for last 30 days. Any help is appreciated. TX