它导致锁定,我需要帮助优化它...
Select o.Vehicle as [No Unit], o.Customer, o.CustomerDisplayName as Name, o.Product as Material, P.ProductName as Product,
o.Depot as Works, a.Distance, o.CustTravelTime as [Assumed TravelTime], o.RequiredDateTime as [Required DateTime],o.TimeWindowOrder
as [To Window Provided],ToWindowDateTime as [Window DateTime],o.OrderRef as [Ref No], o.OrderEntryDateTime as [Orderred DateTime],
o.EnteredBy, o.Instructions, o.Warnings, o.Planning, o.AllocationState as Status,o.LoadDocket as Docket, o.LoadingDateTime
as [Commenced Loading], o.IntransitDateTime as [Completed Loading], o.ArrivedDateTime as [Arrived Customer], o.ArrivedDateTime
as [Commenced Unloading], o.UnloadedDateTime as [Completed Unloading], '?' as [DMS], o.CustomerOrder as CustPO,
o.Renegotiated, o.TurnAround, o.StockOut, o.LateDelivery,o.LateOrder,o.StandingOrder,o.NightShift,o.modifier
as [Actual Modifier], t2.Net, t2.Trantype,o.PlannedDateTime, o.VehAssignedDateTime as [Published Date],
t2.DriverName, o.CancelledDateTime from Orders o left outer join Product P on p.Product = o.Product
left outer join AuthPlantCust A on a.Customer = o.Customer and a.Plant = o.Plant --left
join trans T on O.orderref = t.orderref
outer apply ( SELECT Top 1 Docket, Trantype, DriverName, Net FROM Trans t where o.Orderref = t.Orderref AND TranType <> 'SRT'
ORDER BY DespatchdateTime Desc ) T2 where o.RequiredDateTime >= (@DespatchFrom)
and o.RequiredDateTime < (@DespatchTo) and o.Company = 'C' order by o.RequiredDateTime, o.OrderRef
或建议最佳做法。