BAQ: Calculated Field Concatenate Rows to single field

Thanks. Looking at the XML method, it shows examples of the SQL code, but I don’t have a way to manually change the SQL “Query Phrase”, I have to use the GUI “Query Builder.”
Do I set the query type as a CTE type or keep as TopLevel / InnerSubQuery?
How to I get the SQL code " FOR XML PATH(’’), TYPE).value(’.’, ‘varchar(max)’) "?

You can write that exact thing with the query builder using subqueries

Here is an example @WesAtITC
CustOrder.baq (17.6 KB)


Awesome Jose this is quite a useful query. I have one question. What if you are trying to join something that has a multiple index? For example to concatenate the reference designators on a Job material, for each material one would need to link JobNum,AssemblySeq and MtlSeq.

1 Like

I did something similar for Job Operations on the Subquery, using OprSeq and OpCode:

CAST(JobOper.OprSeq as varchar) + ’ ’ + CAST(JobOper.OpCode as varchar) + ’ ’

And then concatenate the field in the same way on the top level query. Yours should just take one extra level from there.

This fixed my issue.

You can just keep adding rows as well in the sub query. The last row has the XML at the end.

1 Like

Just to make this code even better. I was able to remove the last comma (,) on the string with the following.

REVERSE(stuff(REVERSE(REPLACE(REPLACE({JobnECR} , ‘</Calculated_Calculated_ECR>’,’’),’<Calculated_Calculated_ECR>’,’’)), 1, 1, ‘’))


REPLACE(REPLACE({JobnECR} , ‘</Calculated_Calculated_ECR>’,’’),’<Calculated_Calculated_ECR>’,’’)


Ken, thanks for the help. I was able to narrow it down so that only reference designators related to the material line are brought in.

Getting rid of the superfluous comma also worked great. I learned that pasting straight into BAQ Designer requires replacing all of your single quotes or an error is seen. Also, I think where it says Calculated_Calculated_ECR it should read Calculated_ECR. At least I got correct results when I changed it for my query.

Again, thanks to everyone for taking the time to help with this, it’s super useful, especially with BoMs.

I called my calculated field Calculated_ECR, so it was turned into Calculated_Calculated_ECR lol.

Glad it worked out for ya.

Hi Jose, It looks like you wrote a BAQ for calculated field that would concatenate fields. I can’t open that BAQ. I am looking to concatenate reference designations into one field in BAQ. Would you be able to help? I ma running 9.06.702A progress. Thank you

You can’t do this in 9 in a BAQ

So I have to do it in the report? Are you able to help?

Yes you’ll likely have to do it in the report. You can post your questions to the list @Piotr_Pacholski (new topic please) and someone generally will try to help, there are hundreds of wonderful members on this forum eager and able to help.

1 Like

I just have to tell you, I think I owe you some beer for this example. VERY useful. Thanks for posting it.


I couldn’t figure out how to message you; so sorry for digging up an old thread…

My question is, can I use your example with the REPLACE calc field and add a sum to it? Like in your example, it would be adding up all the order numbers together…

In my example it would be adding up all OnHandQtys for the different locations.
Here’s my query results:

How can I add all the quantities together? Or should I use a different method all together? My goal with this one was to make it all one line instead of having duplicate rows for parts in different locations, and have the total onhand in the last row.

Edit: Also is it possible to remove the zeros at the end of each quantity?

If it was me, I would do another subquery where I used the sum() function and grouped by part number, then you can bring in that subquery like a table and just display the one quantity/part number.

Or grab the OnHand quantity in the Part warehouse table that already has the on hand quantity summed up (although it’s not 100% positive that it matches bin Quantities.)


The top part was it. As usual I was making things more difficult then they had to be.

Thanks Brandon

Hey mark, Were you ever able to figure this out? I am trying to do the same…

I want to relate with multiple indexes for example part, rev, altmethod. Then show the operations for each unique combination of those three. Nothing I try is working!

I did get it working @edlugoposki and for next time I put a little guide in my cheat notes. As mentioned previously this only works in Epicor 10+


Thank you very much! (Go Pack Go :stuck_out_tongue_winking_eye:)

1 Like