I have a server that currently is processing jobs. Example
JobName avgStartTime avgEndTime
job1 00:31:05.5500000 00:37:35.6170000
job2 00:35:05.5500000 00:45:35.6170000
job3 00:54:24.0600000 01:04:22.5700000
job4 05:07:12.9100000 06:04:59.7800000
job5 20:48:04.6870000 21:08:20.1430000
job6 19:40:24.6870000 19:57:48.4570000
and I would like to create a query that would give a column with 15 min increments, and another one with the jobs processed in those 15 mins. For example.
Interval NumberOfJobs JobName
00:00:00 0
00:15:00 0
00:30:00 2 Job1
Job2
00:45:00 Job3
01:00:00 Job3
01:15:00
Here is my query to calculate the 15 min increments.
CREATE TABLE #15MinuteIncrements(Increment DATETIME
, PRIMARY KEY(Increment));
DECLARE @dIncr DATETIME =
(SELECT CONVERT( DATETIME, CONVERT(DATE, GETDATE())));
DECLARE @dEnd DATETIME =
(SELECT CONVERT( DATETIME, CONVERT(DATE,
(SELECT DATEADD(day, 1, GETDATE())))));
WHILE(@dIncr < @dEnd)
BEGIN
INSERT INTO #15MinuteIncrements(Increment)
VALUES
(@dIncr);
SELECT @dIncr = DATEADD(MINUTE, 15, @dIncr);
END;
GO