first of all, I\'m not a native english speaker and this is a hard to explain issue. If you have any doubts, please let me know.
We\'re using a GPS vehicle tracking devi
DECLARE @idFrom as int,
@idTo as int,
@gpsDateFrom as datetime,
@gpsDateTo as datetime
DECLARE VehicleCursor CURSOR FAST_FORWARD FOR
SELECT vehicle_gps_id,
datetimeCol
FROM yourtable
ORDER BY vehicle_gps_id
OPEN VehicleCursor FETCH NEXT FROM VehicleCursor INTO @idFrom, @gpsDateFrom
FETCH NEXT FROM VehicleCursor INTO @idTo, @gpsDateTo
WHILE @@FETCH_STATUS = 0 BEGIN
IF DATEDIFF(MI,@gpsDateFrom,@gpsDateTo) >5
BEGIN
--Break (your code here)
END
SET @idFrom = @idTo
SET @gpsDateFrom = @gpsDateTo
FETCH NEXT FROM VehicleCursor INTO @idTo, @gpsDateTo
END
CLOSE VehicleCursor
DEALLOCATE VehicleCursor
Something like this should work for you. It is a cursor that just runs through all your columns comparing datetimes. You can enter in whatever you want to do into the commented section after the if statement.