Let's assume you register some events, you need to be process. When all other conditions are same, you process those events in order you registered them. When some events are more urgent, you need to process them earlier. I think there you can have 2 possible solutions.
1. Events are registered in table with structure like tblEvents: EventID, EventDateTime, EventInfo, EventPriority, ..., EventStatus, where EventPriority has smallint values like 0, 1, 2, ..., and EventStatus = 0 means event is not closed, and EventStatus = 1 means the event is closed. EventPriority = 0 is lowest priority level. The To Do List of events is returned with query
Code:
SELECT * FROM tblEvents WHERE EventStatus = 0 ORDER BY EventPriority DESC, EventDateTime ASC
2. (On fly!) Events are registered in table with structure like tblEvents: EventID, EventDatetime, ProcessingTime, LastDatetime, EventInfo, ..., EventStatus, where LastDateTime is latest possible time the event must be processed. When LastDateTime is empty, it means the event is processed when there is enough time for this. EventStatus is like p.1. ProcessingTime is estimated time needed to process the event.
You need a saved query like
Code:
qUrgentEvents = SELECT EventID, (LastDateTime - ProcessingTime) AS LastStart FROM tblEvents WHERE EventStatus = 0 AND LastDateTime Is Not Null
You need a saved query like (it returns non-urgent event which has shortest processing time - you can return oldest one instead when you want)
Code:
qTopmostNonurgentEvent = SELECT TOP 1 EventID, ProcessingTime FROM tblEvents WHERE EventStatus = 0 AND LastDateTime Is Null ORDER BY ProcessingTime, EventDateTime
You need a saved query like
Code:
qToDoEvents =
SELECT ue.EventID, ue.LastStart FROM qUrgentEvents ue
UNION
SELECT te.EventID, NOW() AS [LastStart] FROM qTopmostNonurgentEvent te WHERE NOW() + te.ProcessingTime < (SELECT MIN(ue0.LastStart) FROM qUrgentEvents ue0)
Now you can return the To Do list of events, like
Code:
SELECT e.EventID, e.EventInfo, tde.LastStart
FROM (tblEvents e JOIN qToDoEvents tde ON tde.EventID = e.EventID
ORDER BY tde.LastStart ASC