BAQ incorrect syntax near 'FOR'

I would follow @Banderson’s advice and convert that to string_agg.

FOR XML in BAQ - ERP 10 - Epicor User Help Forum (epiusers.help)