FOR XML PATH (''): Echapper des caractères "spéciaux"

Ce code fondamentalement traduit les caractères basée sur la position dans une chaîne de caractère à la même position dans une autre chaîne et il fonctionne pour toutes les lignes de la table.

Lorsque je l'exécute (version simplifiée):

DECLARE @R           char(40)
DECLARE @U           char(40)
SET @R=' abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+'+char(181)
SET @U=REVERSE(@R)

DECLARE @TestTable TABLE (RowID int identity(1,1) primary key, Unreadable  varchar(500))
INSERT INTO @TestTable VALUES ('+µt$zw!*µsu+yt!+s$xy')
INSERT INTO @TestTable VALUES ('%*!!xµpxu!(')
INSERT INTO @TestTable VALUES ('pxpµnxrµu+yµs%$t')


    ;WITH CodeValues AS
    (
    SELECT
        Number,SUBSTRING(@R,Number,1) AS R,ASCII(SUBSTRING(@U,Number,1)) AS UA
        FROM Numbers
        WHERE Number<=LEN(@R)
    )
    SELECT
        t.RowID
            ,(SELECT
                  ''+c.R
                  FROM Numbers               n
                      INNER JOIN CodeValues  c ON ASCII(SUBSTRING(t.Unreadable,n.Number,1))=c.UA
                  WHERE n.Number<=LEN(t.Unreadable) 
                  FOR XML PATH('') 
             ) AS readable
        FROM @TestTable t

Je reçois le texte suivant:

RowID       readable
----------- ---------------------------------------
1           a&#x20;simple&#x20;translation
2           hello&#x20;world
3           wow&#x20;you&#x20;ran&#x20;this

Mais besoin de:

RowID       readable
----------- ---------------------------------------
1           a simple translation
2           hello world
3           wow you ran this

Est-il un moyen, autre que REPLACE()d'avoir des espaces apparaissent correctement? Cela arrive aussi sur les sauts de ligne dans mon code.

Cela peut-il être réécrit dans une meilleure façon? En gros, j'ai juste utilisé le FOR XML PATH('') pour concaténer la ligne individuelle valeurs.

source d'informationauteur KM.