Line 1: Limits the results to 100 rows
Line 2: Subtracting one DateTime from another gives you a new DateTime object... Did you realize your data will return 1900-01-09 05:43:17.000
when you do it that way? Use the
function to give you a unit to work with (in this case minutes). This method with your data returns 11864
Line 4: Use the
to limit your returns to only those where the difference in minutes is greater than 2.
Line 5: Use the
to set which column these will be sorted by.
Notice I removed the CASE statement; it really is not needed for functionality
SELECT TOP (100) AddedToQueue, LastStatusUpdate
, Difference = DateDiff(mi,LastStatusUpdate, AddedToQueue)
WHERE DATEDIFF(mi, AddedToQueue, LastStatusUpdate) > 2
ORDER BY AddedToQueue