I'm looking to create a comma-separated list of values from a SQL Server 2005 table, just like in JanetOhara's question. I'm using a query similar to the one presented in techdo's answer to the question.
Everything is working, except the list of values is getting XML encoded. What should be:
Sports & Recreation,x >= y
Is instead returning as:
Sports & Recreation,x <= y
Is there a way to disable the XML character encoding when using "FOR XML" in SQL Server?
See this post on Creating concatenated delimited string from a SQL result set and avoid character encoding when using “FOR XML PATH”
An alternate approach would be to rely on concatenation of characters (of course sql is not great with string operations as it is developed to work with set theory)
You just need to use the right options with
FOR XML
. Here's one approach that avoids encoding: