I don’t know why but I feel like I’m using the wrong table / field?
I don’t understand why my case statement is not returning correct values in the calculated field.
There is a SalesRep table. Can you create a join in your BAQ to this table based on the SO Sales Rep ID? That will then pull all of the sales rep information that you need.
select distinct
[InvcHead].[SalesRepList] as [InvcHead_SalesRepList],
( (case
when [Customer].[SalesRepCode] = ‘JD’ then ‘Jane Doe’
end)) as [Calculated_FormattedSalesRep],
[InvcHead].[CreditMemo] as [InvcHead_CreditMemo],
[InvcHead].[OpenInvoice] as [InvcHead_OpenInvoice],
[Customer].[CustID] as [Customer_CustID],
[Customer].[Name] as [Customer_Name],
[InvcHead].[InvoiceNum] as [InvcHead_InvoiceNum],
[InvcHead].[InvoiceDate] as [InvcHead_InvoiceDate],
[InvcDtl].[InvoiceLine] as [InvcDtl_InvoiceLine],
[InvcDtl].[PartNum] as [InvcDtl_PartNum],
[InvcDtl].[RevisionNum] as [InvcDtl_RevisionNum],
[InvcDtl].[LineDesc] as [InvcDtl_LineDesc],
[InvcDtl].[OurShipQty] as [InvcDtl_OurShipQty],
[InvcDtl].[IUM] as [InvcDtl_IUM],
[InvcDtl].[DocUnitPrice] as [InvcDtl_DocUnitPrice],
[InvcDtl].[DocExtPrice] as [InvcDtl_DocExtPrice],
[ShipTo].[Name] as [ShipTo_Name],
[ShipTo].[Address1] as [ShipTo_Address1],
[ShipTo].[Address2] as [ShipTo_Address2],
[ShipTo].[City] as [ShipTo_City],
[ShipTo].[State] as [ShipTo_State],
[ShipTo].[ZIP] as [ShipTo_ZIP],
[InvcHead].[DocInvoiceAmt] as [InvcHead_DocInvoiceAmt],
[InvcDtl].[TotalMiscChrg] as [InvcDtl_TotalMiscChrg],
[InvcHead].[OrderNum] as [InvcHead_OrderNum]
from Erp.InvcHead as [InvcHead]
left outer join Erp.InvcDtl as [InvcDtl] on
InvcHead.Company = InvcDtl.Company
and InvcHead.InvoiceNum = InvcDtl.InvoiceNum
left outer join Erp.Customer as [Customer] on
InvcDtl.Company = Customer.Company
and InvcDtl.CustNum = Customer.CustNum
inner join Erp.ShipTo as [ShipTo] on
Customer.Company = ShipTo.Company
and Customer.CustNum = ShipTo.CustNum
and Customer.ShipToNum = ShipTo.ShipToNum
left outer join Erp.SalesRep as [SalesRep] on
ShipTo.Company = SalesRep.Company
and ShipTo.SalesRepCode = SalesRep.SalesRepCode
left outer join Erp.OrderHed as [OrderHed] on
ShipTo.Company = OrderHed.Company
and ShipTo.CustNum = OrderHed.CustNum
and ShipTo.ShipToNum = OrderHed.ShipToNum
I needed to pull the sales rep list from the invoichead table
then create a subquery to bring in the salesrep table, the sales rep code
tie the subquery to the invoichead table
connected the two on Company alone
then added a table criteria to the subquery to bring in the name of the sales rep.
I had to use the function called ‘ranges’