I would like to have the Buyer name and ID on this BAQ I have. I did not make this BAQ. I can connect via Company and I do get the Buyer ID and Name in my results, but it is also giving me a “Severity: Error, Text: Bad SQL statement.” warning and I have to ‘x’ it otherwise it just hangs. Any advice? What is wrong with my connections?
I would remove the PerCon table - it’s not joined to anything an would be creating multiple rows.
Assuming you are single Site - Join the PartPlant to the Part and link the with an inner join PurAgent
Bring in a second purAgent table and inner join it to the PartClass
Thank you for all your suggestions. I was able to get rid of that SQL error and produce a Buyer ID and a Buyer Name on my report.
Now the issue is it’s reporting incorrect information. For example, it’s saying part ABC was purchased by Mr. Smith, but when you actually look at the part it has a different buyer.
Assuming you are getting PurAgent from PartClass and PartPlant you will need to probably use Coalesce something like below. That checks for null and uses the first non null result.
@mlp - if you want to know who is buying the materials, you need to add in PO tables
This query below would show who the buyer is that is buying a part vs who “should be” based on the part class or Part Plant tables.
OK. I tried that but I am having difficulty weaving it in with the other tables I need.
What I have now is okay, it being pulled from the Part Maintenance to tell me who the buyer is. This is a BAQ made by someone else that I am trying to add the Buyer information.
But we noticed that I am still getting duplicates for other columns, this time when it concerns the Bin. Which messes up the calculation.
select
[PartBin].[WarehouseCode] as [PartBin_WarehouseCode],
[Part].[PartNum] as [Part_PartNum],
[Part].[PartDescription] as [Part_PartDescription],
[PartBin].[BinNum] as [PartBin_BinNum],
[PartBin].[OnhandQty] as [PartBin_OnhandQty],
[PartCost].[StdBurdenCost] as [PartCost_StdBurdenCost],
[PartCost].[StdLaborCost] as [PartCost_StdLaborCost],
[PartCost].[StdMaterialCost] as [PartCost_StdMaterialCost],
[PartCost].[StdMtlBurCost] as [PartCost_StdMtlBurCost],
[PartCost].[StdSubContCost] as [PartCost_StdSubContCost],
(PartCost.StdBurdenCost + PartCost.StdLaborCost + PartCost.StdMaterialCost + PartCost.StdMtlBurCost + PartCost.StdSubContCost) as [Calculated_TotalCost],
(PartBin.OnhandQty * TotalCost) as [Calculated_Value],
[ProdGrup].[Description] as [ProdGrup_Description],
[PartClass].[Description] as [PartClass_Description],
[Part].[TypeCode] as [Part_TypeCode],
[ProdGrup].[ProdCode] as [ProdGrup_ProdCode],
[PartClass].[ClassID] as [PartClass_ClassID],
[Warehse].[Plant] as [Warehse_Plant],
[PartCost].[LastLaborCost] as [PartCost_LastLaborCost],
[PartCost].[LastBurdenCost] as [PartCost_LastBurdenCost],
[PartCost].[LastMaterialCost] as [PartCost_LastMaterialCost],
[PartCost].[LastMtlBurCost] as [PartCost_LastMtlBurCost],
[PartBin].[Company] as [PartBin_Company],
(PartBin.OnhandQty * PartCost.LastMaterialCost) as [Calculated_TotCost],
(Coalesce(PurAgent.BuyerID,PurAgent_PartClass.BuyerID)) as [Calculated_Coalesce],
[PurAgent].[Name] as [PurAgent_Name]
from Erp.PartBin as PartBin
inner join Erp.Part as Part on
PartBin.Company = Part.Company
and PartBin.PartNum = Part.PartNum
and ( Part.NonStock <> 1 )
left outer join Erp.ProdGrup as ProdGrup on
Part.Company = ProdGrup.Company
and Part.ProdCode = ProdGrup.ProdCode
left outer join Erp.PartClass as PartClass on
Part.Company = PartClass.Company
and Part.ClassID = PartClass.ClassID
left outer join Erp.PurAgent as PurAgent_PartClass on
PartClass.Company = PurAgent_PartClass.Company
and PartClass.BuyerID = PurAgent_PartClass.BuyerID
inner join Erp.PartPlant as PartPlant on
Part.Company = PartPlant.Company
and Part.PartNum = PartPlant.PartNum
inner join Erp.PurAgent as PurAgent on
PartPlant.Company = PurAgent.Company
and PartPlant.BuyerID = PurAgent.BuyerID
left outer join Erp.PartCost as PartCost on
PartBin.Company = PartCost.Company
and PartBin.PartNum = PartCost.PartNum
inner join Erp.Warehse as Warehse on
PartBin.Company = Warehse.Company
and PartBin.WarehouseCode = Warehse.WarehouseCode
order by Warehse.Plant, Warehse.WarehouseCode, Part.PartNum