I would be inclined to try adding
and s.InspectionDate < i.Departure
to the WHERE clause. That should allow an index to be used, and then the
and s.InspectionDate < dateadd(day, datediff(day, 0, i.Departure), 0)
will fine-filter it
I would be inclined to try adding
and s.InspectionDate < i.Departure
to the WHERE clause. That should allow an index to be used, and then the
and s.InspectionDate < dateadd(day, datediff(day, 0, i.Departure), 0)
will fine-filter it