Why does SQL display an & as &?

sql, t-sql

Solution

It is happening because the strings being combined in the XML statement are using XML specific characters. In addition to &, the also affects < and >, and probably other characters.

I usually fix this be doing a replace after the call:

select @str = replace(@str, '&amp;', '&')

And nesting the replaces for additional characters.

Problem

Possible Duplicate: help with FOR XML PATH('') escaping “special” characters I need some assistance, my query is below: ``` STUFF( ( SELECT ',' + CountDesc FROM Count INNER JOIN ProjectCount ON Count.Id = ProjectCount.CountId WHERE ProjectCount.ProjectId = Project.Id ORDER BY Count.CountDesc FOR XML PATH('') ), 1, 1, '') as [Country] ``` What happens is when i run this query and the Count table has an & in one of its fields, it displays the & as `&amp;`. Is there anyway to not let this happen? Thanks in advance.

Original source

Related problems