Error while using FOR XML PATH statement

I created a BAQ that should concatenate the CommentText field of multiple records into a single column using the FOR XML PATH statement. I am receiving a “Severity: Error, Text: SQL Statement” error when I test the BAQ. I have tried to simplify the query from what I originally had, trying to identify the issue. I also removed the UDField, at one time, and that had no impact. I can not find where my mistake is.

I am hoping that someone can see my mistake since I have been staring at this for a while now.
DG_TEST3.baq (34.3 KB)
Help help!! Thank you

The query phrase text is

The Main Query info


Subquery Info



XML Path For was a hack used until SQL Server provided the String_agg command. Lots of posts here by @Banderson explaining the better way.

2 Likes

I can’t wait to use that function.

First, get rid of the replace stuff and just look at the field without the string manipulation stuff. Then work the replace stuff into it piece by piece.

never mind, if you’re on a modern version, use String_Agg()

2 Likes

I think your new name should be Brandon Aggregate. Or at least make your EpiUsers name @baggregate. It’s kinda a windowing function to your soul. :person_shrugging:

1 Like

Thank you @Mark_Wonsil & @Banderson ! I had not done this since upgrading.