I\'m currently trying to pull some data from a SQL Server database view that we have restricted access to from our Linux web server.
We don\'t need to edit the data
One more factoid for this issue. As of 2015, returning a value of type XML results in the first 256 characters being returned cleanly. However, most of the rest of the XML will be returned as apparently random garbage, with an occasional clear fragment of text. In fact, if I had to guess, the query returns a random block of memory for all characters after 256.
In my specific case, I was generating XML (using multiple FOR XML nested queries) to send to a website for display. In this case, the solution I found was to use the CAST hack, casting the data to varchar(max).
So remember: If you see a block of 256 clear characters followed by random garbage in your query results, it is probably an XML value being returned as an XML type instead of a varchar(max) type.
CAVEAT: This may only apply if the XML is dynamically generated.