I am trying to use the FOR XML PATH "trick" to create one line of text out of several rows, e.g. like in this question: How to concat many rows into one string in SQL Server 2008?
However, SQL Server is returning an error message that says
XML parsing: line 1, character 53, illegal name character
I am unable to figure out what is causing this error. Probably there is something in my data that is does not like... The query in question is a correlated subquery, and is resembling this:
(select my_text_field as [text()]
from child_table
where foreign_key = master_table.id
order by some_sequence
for xml path ('')) as comment
The sheer magnitude of the data involved makes it hard to manually look through the fields for oddities.
Any hints as to how I could resolve this? I was under the impression that FOR XML PATH should be able to escape illegal characters by itself, but maybe not..?