Hi @gpayne, thanks for your help. Here is the query;
select distinct
[OrderHed].[OrderNum] as [OrderHed_OrderNum],
[Customer].[Name] as [Customer_Name],
[OrderHed].[EntryPerson] as [OrderHed_EntryPerson],
[OrderHed].[OrderRecDate_c] as [OrderHed_OrderRecDate_c],
[SubQuery3].[Calculated_NonStandard] as [Calculated_NonStandard],
[SubQuery4].[Calculated_SpecialProduct] as [Calculated_SpecialProduct],
[SubQuery5].[Calculated_DrgCompleteDate] as [Calculated_DrgCompleteDate],
[OrderHed].[OrderDate] as [OrderHed_OrderDate],
[OrderHed].[TotalLines] as [OrderHed_TotalLines],
[OrderHed].[SalesRepList] as [OrderHed_SalesRepList],
[SubQuery2].[Calculated_ReworkLines] as [Calculated_ReworkLines],
[SubQuery7].[Calculated_StorageLine] as [Calculated_StorageLine],
[JobProd].[OrderNum] as [JobProd_OrderNum],
((case when JobProd.OrderNum <> '' then 1 else 0 end)) as [Calculated_JobsCreated],
[OrderHed].[ProjectID_c] as [OrderHed_ProjectID_c],
[Project].[Description] as [Project_Description],
[ShipDtl].[PackNum] as [ShipDtl_PackNum],
[ShipHead].[ShipDate] as [ShipHead_ShipDate],
[OrderHed].[OrderAmt] as [OrderHed_OrderAmt],
[OrderHed].[DocOrderAmt] as [OrderHed_DocOrderAmt],
((case when PartShipAmount.InvoiceValue_InvoiceAmt > 0 then (PartShipAmount.InvoiceValue_InvoiceAmt - OrderHed.DocTotalTax) else OrderHed.DocTotalCharges end)) as [Calculated_orderValue],
[PartShipAmount].[PartShip_InvoiceNum] as [PartShip_InvoiceNum],
[PartShipAmount].[InvoiceValue_InvoiceAmt] as [InvoiceValue_InvoiceAmt],
[PartShipAmount].[PartShip_PackNum] as [PartShip_PackNum],
(DateDiff(dd, OrderHed.OrderRecDate_c, ShipHead.ShipDate)) as [Calculated_PoToShipDays],
(DateDiff(wk, OrderHed.OrderRecDate_c, ShipHead.ShipDate) * 2) as [Calculated_PoToShipWks],
(DateDiff(dd, OrderHed.OrderDate, ShipHead.ShipDate)) as [Calculated_EntToShipDays],
(DateDiff(wk, OrderHed.OrderDate, ShipHead.ShipDate) * 2) as [Calculated_EntToShipWeeks],
(( PoToShipDays - PoToShipWks)) as [Calculated_POtoShip],
(( EntToShipDays - EntToShipWeeks)) as [Calculated_EntryToShip],
(Case When DatePart(weekday, ShipHead.ShipDate) = 7 Then 1 else 0 end) as [Calculated_EndOnSat],
(Case When DatePart(weekday, OrderHed.OrderRecDate_c) = 1 Then 1 else 0 end) as [Calculated_StartOnSun],
(POtoShip - EntryToShip) as [Calculated_LoadDays],
[PartShipAmount].[Calculated_amountPartShip] as [Calculated_amountPartShip]
from Erp.OrderHed as OrderHed
left outer join Erp.Customer as Customer on
OrderHed.BTCustNum = Customer.CustNum
left outer join Erp.JobProd as JobProd on
OrderHed.OrderNum = JobProd.OrderNum
left outer join Erp.Project as Project on
OrderHed.ProjectID_c = Project.ProjectID
left outer join Erp.ShipDtl as ShipDtl on
OrderHed.OrderNum = ShipDtl.OrderNum
left outer join Erp.ShipHead as ShipHead on
ShipDtl.PackNum = ShipHead.PackNum
left outer join (select
[NonStandard].[OrderNum] as [NonStandard_OrderNum],
(sum(
case
when NonStandard.CheckBox03 = 1 then 1
else 0
end
)) as [Calculated_NonStandard]
from Erp.OrderDtl as NonStandard
group by [NonStandard].[OrderNum]) as SubQuery3 on
OrderHed.OrderNum = SubQuery3.NonStandard_OrderNum
left outer join (select
[Special].[OrderNum] as [Special_OrderNum],
(sum(
case
when Special.Checkbox02 = 1 then 1
else 0
end
)) as [Calculated_SpecialProduct]
from Erp.OrderDtl as Special
group by [Special].[OrderNum]) as SubQuery4 on
OrderHed.OrderNum = SubQuery4.Special_OrderNum
left outer join (select distinct
[CAD].[Company] as [CAD_Company],
[CAD].[OrderNum] as [CAD_OrderNum],
(max( QuoteDtl.MdCompDate_c )) as [Calculated_DrgCompleteDate]
from Erp.OrderDtl as CAD
inner join Erp.QuoteDtl as QuoteDtl on
CAD.Company = QuoteDtl.Company
And
CAD.QuoteNum = QuoteDtl.QuoteNum
And
CAD.QuoteLine = QuoteDtl.QuoteLine
group by [CAD].[Company],
[CAD].[OrderNum]) as SubQuery5 on
OrderHed.OrderNum = SubQuery5.CAD_OrderNum
left outer join (select
[PartShip].[Company] as [PartShip_Company],
[PartShip].[InvoiceNum] as [PartShip_InvoiceNum],
[PartShip].[PackNum] as [PartShip_PackNum],
[OrderAmount].[OrderAmt] as [OrderAmount_OrderAmt],
[InvoiceValue].[InvoiceAmt] as [InvoiceValue_InvoiceAmt],
((case when InvoiceValue.InvoiceAmt <> null then InvoiceValue.InvoiceAmt else null end)) as [Calculated_amountPartShip]
from Erp.InvcDtl as PartShip
inner join Erp.InvcHead as InvoiceValue on
PartShip.Company = InvoiceValue.Company
And
PartShip.InvoiceNum = InvoiceValue.InvoiceNum
inner join Erp.OrderHed as OrderAmount on
InvoiceValue.Company = OrderAmount.Company
And
InvoiceValue.OrderNum = OrderAmount.OrderNum) as PartShipAmount on
PartShipAmount.PartShip_PackNum = ShipHead.PackNum
left outer join (select distinct
[OrderDtl4].[OrderNum] as [OrderDtl4_OrderNum],
[OrderDtl4].[LineDesc] as [OrderDtl4_LineDesc],
(case
when
sum(
case
when OrderDtl4.LineDesc = 'Weekely Pallet Charge' then 1
else 0
end
)
> 0 then 1
else 0
end) as [Calculated_StorageLine]
from Erp.OrderDtl as OrderDtl4
group by [OrderDtl4].[OrderNum],
[OrderDtl4].[LineDesc]) as SubQuery7 on
OrderHed.OrderNum = SubQuery7.OrderDtl4_OrderNum
left outer join (select distinct
[OrderHed-Rework].[OrderNum] as [OrderHed-Rework_OrderNum],
(case
when
sum(
case
when OrderDtl.Rework = 1 then 1
else 0
end
)
> 0 then 1
else 0
end) as [Calculated_ReworkLines]
from Erp.OrderHed as OrderHed-Rework
left outer join Erp.OrderDtl as OrderDtl on
OrderHed-Rework.Company = OrderDtl.Company
And
OrderHed-Rework.OrderNum = OrderDtl.OrderNum
group by [OrderHed-Rework].[OrderNum]) as SubQuery2 on
OrderHed.OrderNum = SubQuery2.OrderHed-Rework_OrderNum
where (OrderHed.VoidOrder = false and OrderHed.OrderDate >= DATEADD (day, -2, GETDATE()))
Here is the BAQ itself;
Order-Creation 06-10-2019.baq (106.8 KB)