あなたのサンプル データを [DutyEvents] という名前のテーブルに入れ、一貫性を保つように微調整しました (たとえば、最初の [VehicleName] の最終的な「オフ デューティ」は翌日の午前 3 時です)...
VehicleName EventDate Message
----------- ------------------- -------
071-314 2012-09-28 17:00:00 On Duty
071-314 2012-09-28 18:00:00 Driving
071-314 2012-09-28 19:00:00 On Duty
071-314 2012-09-28 20:00:00 Driving
071-314 2012-09-29 03:00:00 Off Duty
071-315 2012-09-28 04:00:00 Driving
071-315 2012-09-28 05:00:00 On Duty
071-315 2012-09-28 06:00:00 Driving
071-315 2012-09-28 07:00:00 On Duty
071-315 2012-09-28 09:00:00 Off Duty
...次に、次の Access クエリを作成しました...
SELECT VehicleName, Message, EventDate AS Start, NextEventDate as End,
Round((NextEventDate - EventDate) * 24, 0) AS Hours
FROM
(
SELECT de.VehicleName, de.EventDate, de.Message,
(SELECT TOP 1 EventDate FROM DutyEvents
WHERE VehicleName = de.VehicleName
AND EventDate > de.EventDate ORDER BY EventDate
) AS NextEventDate
FROM DutyEvents de
WHERE de.Message <> "Off Duty"
)
...次の結果が生成されます...
VehicleName Message Start End Hours
----------- ------- ------------------- ------------------- -----
071-314 On Duty 2012-09-28 17:00:00 2012-09-28 18:00:00 1
071-314 Driving 2012-09-28 18:00:00 2012-09-28 19:00:00 1
071-314 On Duty 2012-09-28 19:00:00 2012-09-28 20:00:00 1
071-314 Driving 2012-09-28 20:00:00 2012-09-29 03:00:00 7
071-315 Driving 2012-09-28 04:00:00 2012-09-28 05:00:00 1
071-315 On Duty 2012-09-28 05:00:00 2012-09-28 06:00:00 1
071-315 Driving 2012-09-28 06:00:00 2012-09-28 07:00:00 1
071-315 On Duty 2012-09-28 07:00:00 2012-09-28 09:00:00 2
それはあなたが探していたものですか?