Need some help to verify this is the correct way of obtaining the result. I need to find the variance in minutes between two dates where the seconds portion of the date > 0.
List for the past minute, Variance = (Event_BeginTime - Event_CreateDate) where the seconds portion of HH:MM:SS > 0
SELECT Event_BeginTime
,Event_CreateDate
,DATEDIFF(MINUTE,Event_BeginTime,Event_CreateDate) AS 'Variance'
FROM Events WITH (NOLOCK)
WHERE RIGHT(CAST(Event_BeginTime AS TIME(0)), 2) > 0 AND Event_CreateDate >= DATEADD(MINUTE, -1, GETDATE())
ORDER BY Event_CreateDate DESC
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `Events` ADD INDEX `events_idx_event_createdate` (`Event_CreateDate`);
SELECT
Events.Event_BeginTime,
Events.Event_CreateDate,
DATEDIFF(MINUTE,
Events.Event_BeginTime,
Events.Event_CreateDate) AS 'Variance'
FROM
Events WITH (NOLOCK)
WHERE
RIGHT(CAST(Events.Event_BeginTime AS TIME (0)), 2) > 0
AND Events.Event_CreateDate >= DATEADD(MINUTE, -1, GETDATE()) ORDER BY
Events.Event_CreateDate DESC