Skip to main content

SQL Server function to decode HTML.

create function dbo.udf_HtmlDecode
(
    @text nvarchar(max)
)
returns nvarchar(max)
as
begin
    declare @vcResult nvarchar(max);
    declare @vcCrLf nvarchar(4);
    declare @siPos smallint;
    declare @vcEncoded nvarchar(7);
    declare @siChar smallint;

    set @vcCrLf = char(13) + char(10);

    select @vcResult = @text;
    select @siPos = patindex('%&#___;%', @vcResult);

    while (@siPos > 0)
    begin
        select @vcEncoded = substring(@vcResult, @siPos, 6);
        select @siChar = cast(substring(@vcEncoded, 3, 3) as smallint);
        select @vcResult = replace(@vcResult, @vcEncoded, nchar(@siChar));
        select @siPos = patindex('%&#___;%', @vcResult);
    end;

    select @siPos = patindex('%&#____;%', @vcResult);
    while (@siPos > 0)
    begin
        select @vcEncoded = substring(@vcResult, @siPos, 7);
        select @siChar = cast(substring(@vcEncoded, 3, 4) as smallint);
        select @vcResult = replace(@vcResult, @vcEncoded, nchar(@siChar));
        select @siPos = patindex('%&#____;%', @vcResult);
    end;

    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '"', nchar(0x0022));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&', nchar(0x0026));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '<', nchar(0x003c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '>', nchar(0x003e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&nbsp;', nchar(0x00a0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&iexcl;', nchar(0x00a1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&cent;', nchar(0x00a2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&pound;', nchar(0x00a3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&curren;', nchar(0x00a4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&yen;', nchar(0x00a5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&brvbar;', nchar(0x00a6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sect;', nchar(0x00a7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&uml;', nchar(0x00a8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&copy;', nchar(0x00a9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ordf;', nchar(0x00aa));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&laquo;', nchar(0x00ab));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&not;', nchar(0x00ac));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&shy;', nchar(0x00ad));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&reg;', nchar(0x00ae));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&macr;', nchar(0x00af));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&deg;', nchar(0x00b0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&plusmn;', nchar(0x00b1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sup2;', nchar(0x00b2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sup3;', nchar(0x00b3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&acute;', nchar(0x00b4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&micro;', nchar(0x00b5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&para;', nchar(0x00b6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&middot;', nchar(0x00b7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&cedil;', nchar(0x00b8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sup1;', nchar(0x00b9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ordm;', nchar(0x00ba));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&raquo;', nchar(0x00bb));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&frac14;', nchar(0x00bc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&frac12;', nchar(0x00bd));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&frac34;', nchar(0x00be));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&iquest;', nchar(0x00bf));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Agrave;', nchar(0x00c0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Aacute;', nchar(0x00c1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Acirc;', nchar(0x00c2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Atilde;', nchar(0x00c3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Auml;', nchar(0x00c4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Aring;', nchar(0x00c5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&AElig;', nchar(0x00c6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ccedil;', nchar(0x00c7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Egrave;', nchar(0x00c8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Eacute;', nchar(0x00c9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ecirc;', nchar(0x00ca));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Euml;', nchar(0x00cb));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Igrave;', nchar(0x00cc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Iacute;', nchar(0x00cd));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Icirc;', nchar(0x00ce));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Iuml;', nchar(0x00cf));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ETH;', nchar(0x00d0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ntilde;', nchar(0x00d1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ograve;', nchar(0x00d2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Oacute;', nchar(0x00d3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ocirc;', nchar(0x00d4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Otilde;', nchar(0x00d5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ouml;', nchar(0x00d6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&times;', nchar(0x00d7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Oslash;', nchar(0x00d8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ugrave;', nchar(0x00d9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Uacute;', nchar(0x00da));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Ucirc;', nchar(0x00db));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Uuml;', nchar(0x00dc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Yacute;', nchar(0x00dd));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&THORN;', nchar(0x00de));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&szlig;', nchar(0x00df));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&agrave;', nchar(0x00e0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&aacute;', nchar(0x00e1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&acirc;', nchar(0x00e2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&atilde;', nchar(0x00e3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&auml;', nchar(0x00e4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&aring;', nchar(0x00e5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&aelig;', nchar(0x00e6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ccedil;', nchar(0x00e7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&egrave;', nchar(0x00e8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&eacute;', nchar(0x00e9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ecirc;', nchar(0x00ea));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&euml;', nchar(0x00eb));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&igrave;', nchar(0x00ec));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&iacute;', nchar(0x00ed));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&icirc;', nchar(0x00ee));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&iuml;', nchar(0x00ef));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&eth;', nchar(0x00f0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ntilde;', nchar(0x00f1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ograve;', nchar(0x00f2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&oacute;', nchar(0x00f3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ocirc;', nchar(0x00f4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&otilde;', nchar(0x00f5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ouml;', nchar(0x00f6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&divide;', nchar(0x00f7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&oslash;', nchar(0x00f8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ugrave;', nchar(0x00f9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&uacute;', nchar(0x00fa));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ucirc;', nchar(0x00fb));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&uuml;', nchar(0x00fc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&yacute;', nchar(0x00fd));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&thorn;', nchar(0x00fe));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&yuml;', nchar(0x00ff));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&OElig;', nchar(0x0152));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&oelig;', nchar(0x0153));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Scaron;', nchar(0x0160));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&scaron;', nchar(0x0161));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Yuml;', nchar(0x0178));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&fnof;', nchar(0x0192));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&circ;', nchar(0x02c6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&tilde;', nchar(0x02dc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Alpha;', nchar(0x0391));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Beta;', nchar(0x0392));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Gamma;', nchar(0x0393));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Delta;', nchar(0x0394));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Epsilon;', nchar(0x0395));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Zeta;', nchar(0x0396));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Eta;', nchar(0x0397));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Theta;', nchar(0x0398));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Iota;', nchar(0x0399));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Kappa;', nchar(0x039a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Lambda;', nchar(0x039b));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Mu;', nchar(0x039c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Nu;', nchar(0x039d));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Xi;', nchar(0x039e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Omicron;', nchar(0x039f));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Pi;', nchar(0x03a0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '& Rho ;', nchar(0x03a1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Sigma;', nchar(0x03a3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Tau;', nchar(0x03a4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Upsilon;', nchar(0x03a5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Phi;', nchar(0x03a6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Chi;', nchar(0x03a7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Psi;', nchar(0x03a8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Omega;', nchar(0x03a9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&alpha;', nchar(0x03b1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&beta;', nchar(0x03b2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&gamma;', nchar(0x03b3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&delta;', nchar(0x03b4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&epsilon;', nchar(0x03b5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&zeta;', nchar(0x03b6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&eta;', nchar(0x03b7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&theta;', nchar(0x03b8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&iota;', nchar(0x03b9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&kappa;', nchar(0x03ba));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lambda;', nchar(0x03bb));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&mu;', nchar(0x03bc));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&nu;', nchar(0x03bd));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&xi;', nchar(0x03be));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&omicron;', nchar(0x03bf));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&pi;', nchar(0x03c0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rho;', nchar(0x03c1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sigmaf;', nchar(0x03c2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sigma;', nchar(0x03c3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&tau;', nchar(0x03c4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&upsilon;', nchar(0x03c5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&phi;', nchar(0x03c6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&chi;', nchar(0x03c7));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&psi;', nchar(0x03c8));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&omega;', nchar(0x03c9));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&thetasym;', nchar(0x03d1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&upsih;', nchar(0x03d2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&piv;', nchar(0x03d6));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ensp;', nchar(0x2002));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&emsp;', nchar(0x2003));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&thinsp;', nchar(0x2009));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&zwnj;', nchar(0x200c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&zwj;', nchar(0x200d));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lrm;', nchar(0x200e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rlm;', nchar(0x200f));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ndash;', nchar(0x2013));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&mdash;', nchar(0x2014));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lsquo;', nchar(0x2018));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rsquo;', nchar(0x2019));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sbquo;', nchar(0x201a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ldquo;', nchar(0x201c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rdquo;', nchar(0x201d));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&bdquo;', nchar(0x201e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&dagger;', nchar(0x2020));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Dagger;', nchar(0x2021));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&bull;', nchar(0x2022));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&hellip;', nchar(0x2026));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&permil;', nchar(0x2030));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&prime;', nchar(0x2032));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&Prime;', nchar(0x2033));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lsaquo;', nchar(0x2039));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rsaquo;', nchar(0x203a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&oline;', nchar(0x203e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&frasl;', nchar(0x2044));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&euro;', nchar(0x20ac));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&image;', nchar(0x2111));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&weierp;', nchar(0x2118));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&real;', nchar(0x211c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&trade;', nchar(0x2122));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&alefsym;', nchar(0x2135));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&larr;', nchar(0x2190));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&uarr;', nchar(0x2191));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rarr;', nchar(0x2192));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&darr;', nchar(0x2193));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&harr;', nchar(0x2194));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&crarr;', nchar(0x21b5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lArr;', nchar(0x21d0));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&uArr;', nchar(0x21d1));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rArr;', nchar(0x21d2));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&dArr;', nchar(0x21d3));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&hArr;', nchar(0x21d4));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&forall;', nchar(0x2200));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&part;', nchar(0x2202));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&exist;', nchar(0x2203));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&empty;', nchar(0x2205));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&nabla;', nchar(0x2207));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&isin;', nchar(0x2208));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&notin;', nchar(0x2209));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ni;', nchar(0x220b));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&prod;', nchar(0x220f));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sum;', nchar(0x2211));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&minus;', nchar(0x2212));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lowast;', nchar(0x2217));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&radic;', nchar(0x221a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&prop;', nchar(0x221d));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&infin;', nchar(0x221e));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ang;', nchar(0x2220));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&and;', nchar(0x2227));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&or;', nchar(0x2228));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&cap;', nchar(0x2229));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&cup;', nchar(0x222a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&int;', nchar(0x222b));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&there4;', nchar(0x2234));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sim;', nchar(0x223c));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&cong;', nchar(0x2245));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&asymp;', nchar(0x2248));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ne;', nchar(0x2260));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&equiv;', nchar(0x2261));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&le;', nchar(0x2264));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&ge;', nchar(0x2265));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sub;', nchar(0x2282));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sup;', nchar(0x2283));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&nsub;', nchar(0x2284));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sube;', nchar(0x2286));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&supe;', nchar(0x2287));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&oplus;', nchar(0x2295));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&otimes;', nchar(0x2297));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&perp;', nchar(0x22a5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&sdot;', nchar(0x22c5));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lceil;', nchar(0x2308));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rceil;', nchar(0x2309));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lfloor;', nchar(0x230a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rfloor;', nchar(0x230b));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&lang;', nchar(0x2329));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&rang;', nchar(0x232a));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&loz;', nchar(0x25ca));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&spades;', nchar(0x2660));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&clubs;', nchar(0x2663));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&hearts;', nchar(0x2665));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '&diams;', nchar(0x2666));
    select @vcResult = replace(@vcResult collate Latin1_General_CS_AS, '<p>', @vcCrLf);

    return @vcResult;
end;
go