Simplified table structure (the tables can't be merged at this time):
TableA:
dts_received (datetime)
dts_completed (datetime)
task_a (varchar)
TableB:
dts_started (datetime)
task_b (varchar)
What I would like to do is determine how long a task took to complete.
The join parameter would be something like
ON task_a = task_b AND dts_completed < dts_started
The issue is that there may be multiple date-times that occur after the dts_completed.
How do I create a join that only returns the first tableB-datetime that occurs after the tableA-datetime?