问题
How can I convert/decode a text in غلامحسين
format to normal text? I'm using SQL server 2012. I just want to update all of them to normal text.

回答1:
If you know Firstname and Lastname are valid when interpreted as XML, then this will do:
UPDATE _table_
SET Firstname = CONVERT(NVARCHAR(MAX), CONVERT(XML, FirstName)),
Lastname = CONVERT(NVARCHAR(MAX), CONVERT(XML, LastName))
The XML parser will decode the entities for you.
回答2:
For some reason Jeroen's answer doesn't seem to work for me in SQL Server 2016.
The function below works... same principle, just executed differently.
create function dbo.xmlDecode (@string nvarchar(max))
returns varchar(max)
begin
return cast(@string as XML).value('.[1]','nvarchar(max)' )
end;
来源:https://stackoverflow.com/questions/28504103/how-to-decode-xml-entities-in-sql