In my case, I want to connect the AprvMfg table and Manufacturer table such that each row of my result set consists of one column containing the part number and a second containing a list of all manufacturers for that parts. I even downloaded and imported the sample BAQ from @josecgomez and tweaked it for my needs. Yet my result still is like this (looking at three different parts for testing):
select
[InvcHead].[Company] as [InvcHead_Company],
[InvcHead].[InvoiceNum] as [InvcHead_InvoiceNum],
(String_Agg(OrderNums.InvcDtl1_OrderNum,', ')) as [Calculated_SONum]
from Erp.InvcHead as InvcHead
left outer join (select distinct
[InvcDtl1].[Company] as [InvcDtl1_Company],
[InvcDtl1].[InvoiceNum] as [InvcDtl1_InvoiceNum],
[InvcDtl1].[OrderNum] as [InvcDtl1_OrderNum]
from Erp.InvcDtl as InvcDtl1) as OrderNums on
InvcHead.Company = OrderNums.InvcDtl1_Company
and InvcHead.InvoiceNum = OrderNums.InvcDtl1_InvoiceNum
group by [InvcHead].[Company],
[InvcHead].[InvoiceNum]
Looks right per Jose’s BAQ which works. Have you tried swapping the tables so Manufacturer is the top table? We don’t use these tables so I have no data to test with.
select
[AprvMfg].[PartNum] as [AprvMfg_PartNum],
(REPLACE(REPLACE(((select distinct
(',' + Manufacturer.Name) as [Calculated_Name]
from Erp.Manufacturer as Manufacturer
where (Manufacturer.MfgNum = AprvMfg.MfgNum FOR XML PATH('')))) , '</Calculated_Name>',''),'<Calculated_Name>','')) as [Calculated_Names]
from Erp.AprvMfg as AprvMfg