How to write this Subquery

Hi, Sorry if this is current out there right. All of the searches seem to be limited to basic understanding of Subqueries. I am trying to write what I think is a simple query and Concatenate the same field from different rows. I can do it from the SQL Server, but I have not figured it out in Epicor. If someone can point me to a YoutTube or website on how to do this kind of query, or make it and attach it so I can see how it is done in Epicor, I would be so thankful. Here is my query.

SELECT B.Company
, B.LotNum
, B.PartNum
, C.Description AS [Class]
, B.OnhandQty
, STUFF((SELECT Nā€™, ā€™ + CONVERT(varchar(15), R.PONUM) FROM erp.RcvDtl AS R WHERE B.Company = R.Company AND B.PartNum = R.PartNum AND B.LotNum = R.LotNum AND R.ReceiptType = ā€˜Pā€™
FOR XML PATH(ā€™ā€™)), 1, 1, Nā€™ā€™) AS [POs]

FROM erp.PartBin AS B
inner join erp.Part AS P ON B.Company = P.Company AND B.PartNum = P.PartNum
inner join erp.PartClass AS C ON P.Company = C.Company AND P.ClassID = C.ClassID
WHERE Len(B.LotNum) > 0
GO

There is already a long winded example of how to do this in the forum that I wrote a few months back. Including a downloadable sample (seach box top right should help) :slight_smile:
image

3 Likes