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
Sådan noget burde virke for dig. Det er en markør, der bare kører gennem alle dine kolonner og sammenligner dato og klokkeslæt. Du kan indtaste, hvad du vil, i den kommenterede sektion efter if-sætningen.