A BAQ someone else wrote is suddenly timing out today. I can get it to work (though it still takes a looong time) if I remove the all the Order By clauses at the end. Any idea how I can get this running fast enough to not time out again?
select
[Customer].[Name] as [Customer_Name],
[OrderDtl].[OrderNum] as [OrderDtl_OrderNum],
[OrderDtl].[OrderLine] as [OrderDtl_OrderLine],
[OrderRel].[OrderRelNum] as [OrderRel_OrderRelNum],
[JobProd].[JobNum] as [JobProd_JobNum],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
[OrderDtl].[LineDesc] as [OrderDtl_LineDesc],
[JobProd].[ProdQty] as [JobProd_ProdQty],
[JobHead].[QtyCompleted] as [JobHead_QtyCompleted],
[OrderDtl].[OrderQty] as [OrderDtl_OrderQty],
[OrderRel].[OurReqQty] as [OrderRel_OurReqQty],
[OrderRel].[OpenRelease] as [OrderRel_OpenRelease],
[ProdGrup].[Description] as [ProdGrup_Description],
[OrderHed].[OrderDate] as [OrderHed_OrderDate],
[OrderHed].[EntryPerson] as [OrderHed_EntryPerson],
[JobHead].[CreateDate] as [JobHead_CreateDate],
[JobHead].[CreatedBy] as [JobHead_CreatedBy],
[ShipVia].[Description] as [ShipVia_Description],
[OrderRel].[ShipViaCode] as [OrderRel_ShipViaCode],
[OrderDtl].[OpenLine] as [OrderDtl_OpenLine],
[OrderHed].[PONum] as [OrderHed_PONum],
[OrderHed].[OrderHeld] as [OrderHed_OrderHeld],
[OrderRel].[BuyToOrder] as [OrderRel_BuyToOrder],
[OrderRel].[DropShip] as [OrderRel_DropShip],
[Vendor].[Name] as [Vendor_Name],
[POHeader].[PONum] as [POHeader_PONum],
[POHeader].[OrderDate] as [POHeader_OrderDate],
[JobHead].[ReqDueDate] as [JobHead_ReqDueDate],
[OrderDtl].[NeedByDate] as [OrderDtl_NeedByDate],
[OrderRel].[NeedByDate] as [OrderRel_NeedByDate],
[OrderRel].[ShipToNum] as [OrderRel_ShipToNum],
[ShipTo].[Address1] as [ShipTo_Address1],
[OrderHed].[ShipComment] as [OrderHed_ShipComment],
[ShipDtl].[PackNum] as [ShipDtl_PackNum],
[ShipDtl].[PackLine] as [ShipDtl_PackLine]
from Erp.OrderDtl as OrderDtl
left outer join Erp.OrderRel as OrderRel on
OrderDtl.Company = OrderRel.Company
and OrderDtl.OrderNum = OrderRel.OrderNum
and OrderDtl.OrderLine = OrderRel.OrderLine
and ( OrderRel.ReqDate >= '01/01/2017' and OrderRel.OpenRelease = 1 )
left outer join Erp.JobProd as JobProd on
OrderRel.Company = JobProd.Company
and OrderRel.OrderNum = JobProd.OrderNum
and OrderRel.OrderLine = JobProd.OrderLine
and OrderRel.OrderRelNum = JobProd.OrderRelNum
left outer join Erp.JobHead as JobHead on
JobProd.Company = JobHead.Company
and JobProd.JobNum = JobHead.JobNum
left outer join Erp.Vendor as Vendor on
OrderRel.Company = Vendor.Company
and OrderRel.VendorNum = Vendor.VendorNum
left outer join Erp.POHeader as POHeader on
OrderRel.Company = POHeader.Company
and OrderRel.PONum = POHeader.PONum
left outer join Erp.ShipVia as ShipVia on
OrderRel.Company = ShipVia.Company
and OrderRel.ShipViaCode = ShipVia.ShipViaCode
left outer join Erp.ShipTo as ShipTo on
OrderRel.Company = ShipTo.Company
and OrderRel.ShipToNum = ShipTo.ShipToNum
inner join Erp.Customer as Customer on
Customer.Company = ShipTo.Company
and Customer.CustNum = ShipTo.CustNum
inner join Erp.OrderHed as OrderHed on
OrderDtl.Company = OrderHed.Company
and OrderDtl.OrderNum = OrderHed.OrderNum
inner join Erp.OrderHed as OrderHed
and
OrderHed.Company = Customer.Company
and OrderHed.CustNum = Customer.CustNum
left outer join Erp.ShipDtl as ShipDtl on
ShipDtl.Company = OrderRel.Company
and ShipDtl.OrderNum = OrderRel.OrderNum
and ShipDtl.OrderLine = OrderRel.OrderLine
and ShipDtl.OrderRelNum = OrderRel.OrderRelNum
left outer join Erp.ShipDtl as ShipDtl
and
Customer.Company = ShipDtl.Company
and Customer.CustNum = ShipDtl.CustNum
left outer join Erp.ProdGrup as ProdGrup on
OrderDtl.Company = ProdGrup.Company
and OrderDtl.ProdCode = ProdGrup.ProdCode
where (OrderDtl.OpenLine = 1)
order by ProdGrup.Description, OrderRel.NeedByDate, OrderHed.OrderNum, OrderDtl.OrderLine, OrderRel.OrderRelNum