title: Encoding a SQL Server SELECT statement for HTML output
body: <p>I have this <code>SELECT</code> statement that I will be using in a SQL Server 2016 stored procedure:</p>
  
  <pre><code>IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL 
        DROP Table #TempTable
  
  SELECT DISTINCT      
      STUFF((SELECT ', '+  CASE WHEN AU1.Color IS NOT NULL THEN  +'&lt;b&gt;&lt;font color="' + AU1.Color + '"&gt;' + AU1.LastName+ ' ' + AU1.Initials + '&lt;/font&gt;&lt;/b&gt;' +  CHAR(10) ELSE
              AU1.LastName + ' ' + AU1.Initials END  AS [text()]
             FROM 
                 dbo.[Publication.PubMed.Author] AU1
             WHERE 
                 AU1.PMID = 30579772 
             ORDER BY 
                 AU1.PMID
             FOR XML PATH('')), 1, 1, '') AS authorList
  INTO 
      #TempTable
  
  SELECT * FROM #TempTable
  </code></pre>
  
  <p>And I want to save it with the &lt; and > and when I have this as part of a larger SELECT statement it does but when I pull it out to run on it's own it does not.  I have what I through was the answer with the [text()] but that does not help.  The code gets put into an Word document as an HTML string and I it to run correctly.  Should I store it encoded and worry about decoding on the endusers side?  or can I store the html formatted string? </p>
  
  <p>I get</p>
  
  <pre><code>  Rodenbach RA, Norton SA, Wittink MN, &amp;lt;b&amp;gt;&amp;lt;font color="Blue"&amp;gt;Mohile S&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt; 
  </code></pre>
  
  <p>and I want </p>
  
  <pre><code> Rodenbach RA, Norton SA, Wittink MN, &lt;b&gt;&lt;font color="Blue"&gt;Mohile S&lt;/font&gt;&lt;/b&gt; 
  </code></pre>
  
  <p>What am I doing wrong?  Thanks</p>