Thanks for the feedback Remou.
As indicated in the initial post I was unsure on how to get this started using sql as opposed to the access query gui.
A colleague created the following, using sql server, and I will now have a go at translating this into a code which I can use in access.
If anyone can offer any assistence in this translation process it would be most appreciated.
thanks
declare @time_of_day datetime
set @time_of_day = '1/1/1900 8:30:00'
select Operation.[op date],
Operation.theatre,
[Operation id],
--calc delay = start time - (later of "" end time OR @Time_of_day)
[first operation].[arrive theatre] - isnull([Operation in progress].[depart theatre], Operation.[op date] + @time_of_day) as [start delay]
from Operation --the operations
inner join (
select [op date], --the first operation begining after @time_of_day for each day and theatre
Theatre,
min([arrive theatre]) as [arrive theatre]
from Operation
where [arrive theatre] > [op date] + @time_of_day
group by [op date],
Theatre
) as [first operation] on Operation.[op date] = [first operation].[op date]
and Operation.[arrive theatre] = [first operation].[arrive theatre]
and Operation.Theatre = [first operation].Theatre
left join (
select [op date], --end time of any operation "in progress" at @time_of_day
Theatre,
min([depart theatre]) as [depart theatre]
from Operation
where [op date] + @time_of_day between [arrive theatre] and [depart theatre]
group by [op date],
Theatre
) as [Operation in progress] on Operation.[op date] = [Operation in progress].[op date]
and Operation.Theatre = [Operation in progress].Theatre
order by Operation.[op date],
Operation.theatre