I understand what both of you are saying and I have tried both solutions, but I’m not sure I explained myself sufficiently.
Right now I have a Subquery that sums the WIPQty and a Subquery that sums the OnHand Qty and a third Subquery that adds the two together.
I’ve tried adding the code mentioned in both your posts at the Subquery level of WIPQty and when that didn’t seem to work I added the code to the 3rd subquery where I am adding the two together. Neither seemed to work.
Perhaps one of you can tell me what I’m missing?
Thank you for your patience!
I don’t know if the code here will help you understand what I’m doing - but here it is. Unfortunately I am only familiar with BAQ Designer and not so much the code.
select
[Part].[PartNum] as [Part_PartNum],
[Part].[NonStock] as [Part_NonStock],
[Part].[ProdCode] as [Part_ProdCode],
[PartPlant].[MinimumQty] as [PartPlant_MinimumQty],
[PartPlant].[MinMfgLotSize] as [PartPlant_MinMfgLotSize],
[SubQuery3].[Calculated_OnHand] as [Calculated_OnHand],
[SubQuery2].[Calculated_WipQty] as [Calculated_WipQty],
[SubQuery5].[Calculated_Total] as [Calculated_Total]
from Erp.Part as Part
left outer join (select
[Part1].[PartNum] as [Part1_PartNum],
[JobProd].[WIPQty] as [JobProd_WIPQty],
(sum( JobProd.WIPQty )) as [Calculated_WipQty]
from Erp.Part as Part1
inner join Erp.JobHead as JobHead on
Part1.Company = JobHead.Company
and Part1.PartNum = JobHead.PartNum
and ( JobHead.JobClosed <> TRUE and JobHead.JobReleased = Yes )
inner join Erp.JobProd as JobProd on
JobHead.Company = JobProd.Company
and JobHead.JobNum = JobProd.JobNum
where (Part1.InActive = NO)
group by [Part1].[PartNum],
[JobProd].[WIPQty]) as SubQuery2 on
SubQuery2.Part1_PartNum = Part.PartNum
left outer join (select
[Part2].[PartNum] as [Part2_PartNum],
(sum( PartBin.OnhandQty )) as [Calculated_OnHand]
from Erp.Part as Part2
inner join Erp.PartBin as PartBin on
Part2.Company = PartBin.Company
and Part2.PartNum = PartBin.PartNum
and ( not PartBin.BinNum like '%MRB' )
where (Part2.InActive = NO)
group by [Part2].[PartNum]) as SubQuery3 on
SubQuery3.Part2_PartNum = Part.PartNum
inner join Erp.PartPlant as PartPlant on
Part.Company = PartPlant.Company
and Part.PartNum = PartPlant.PartNum
left outer join Erp.PartDtl as PartDtl on
Part.Company = PartDtl.Company
and Part.PartNum = PartDtl.PartNum
left outer join Erp.Customer as Customer on
Customer.Company = PartDtl.Company
and Customer.CustNum = PartDtl.CustNum
left outer join (select
[Part3].[PartNum] as [Part3_PartNum],
(Isnull(SubQuery21.Calculated_WipQty,0) + (SubQuery31.Calculated_OnHand)) as [Calculated_Total],
[SubQuery21].[Calculated_WipQty] as [Calculated_WipQty],
[SubQuery31].[Calculated_OnHand] as [Calculated_OnHand]
from Erp.Part as Part3
inner join (select
[Part1].[PartNum] as [Part1_PartNum],
[JobProd].[WIPQty] as [JobProd_WIPQty],
(sum( JobProd.WIPQty )) as [Calculated_WipQty]
from Erp.Part as Part1
inner join Erp.JobHead as JobHead on
Part1.Company = JobHead.Company
and Part1.PartNum = JobHead.PartNum
and ( JobHead.JobClosed <> TRUE and JobHead.JobReleased = Yes )
inner join Erp.JobProd as JobProd on
JobHead.Company = JobProd.Company
and JobHead.JobNum = JobProd.JobNum
where (Part1.InActive = NO)
group by [Part1].[PartNum],
[JobProd].[WIPQty]) as SubQuery21 on
SubQuery21.Part1_PartNum = Part3.PartNum
inner join (select
[Part2].[PartNum] as [Part2_PartNum],
(sum( PartBin.OnhandQty )) as [Calculated_OnHand]
from Erp.Part as Part2
inner join Erp.PartBin as PartBin on
Part2.Company = PartBin.Company
and Part2.PartNum = PartBin.PartNum
and ( not PartBin.BinNum like '%MRB' )
where (Part2.InActive = NO)
group by [Part2].[PartNum]) as SubQuery31 on
SubQuery31.Part2_PartNum = Part3.PartNum
where (Part3.InActive = NO)
group by [Part3].[PartNum],
[SubQuery21].[Calculated_WipQty],
[SubQuery31].[Calculated_OnHand]) as SubQuery5 on
SubQuery5.Part3_PartNum = Part.PartNum
where (Part.InActive = NO and Part.ProdCode like '%PAR' and Part.NonStock <> TRUE)
group by [Part].[PartNum],
[Part].[NonStock],
[Part].[ProdCode],
[PartPlant].[MinimumQty],
[PartPlant].[MinMfgLotSize],
[SubQuery3].[Calculated_OnHand],
[SubQuery2].[Calculated_WipQty],
[SubQuery5].[Calculated_Total]