title: SQL Server Management Studio format query output into an HTML table
body: <p>I use the following code (below) to create a tabular html email output, but my question is how to change the color one the data in the columns. Can someone tell me how to make the color of s.ADDED_BY as 'td' red.</p>
  
  <pre><code>begin
  
  DECLARE @xml NVARCHAR(MAX)
  DECLARE @body NVARCHAR(MAX)
  SET @xml = CAST((SELECT s.acct_no as 'td', '', s.ADDRESS1 as 'td', '', s.CITY as 'td', '',s.U_WATERCO as 'td', '', s.ADDED_BY as 'td'
  from  PLshared.dbo.client s
  where (U_WATERCO = '' OR U_WATERCO LIKE '%UNKNOW%')
  and s.COUNTY = 'NASSAU'
  and s.inactive &lt;&gt; 'B'
  AND s.DATE_ADDED &gt;= CONVERT(char(10), getdate()-120, 121)
  order by city
  FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
  
  SET @body ='&lt;html&gt;&lt;body&gt;&lt;H3&gt;Clients In Nassau County with no Water Dept&lt;/H3&gt;
  &lt;table border = 1&gt; 
  &lt;tr&gt;
  &lt;th&gt; Acct No &lt;/th&gt; &lt;th&gt; Address &lt;/th&gt; &lt;th&gt; City &lt;/th&gt; &lt;th&gt; WaterCo &lt;/th&gt; &lt;th&gt; AddedBy &lt;/th&gt; &lt;/tr&gt;'    
  
  
  SET @body = @body + @xml +'&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'
  
  
  EXEC msdb.dbo.sp_send_dbmail
  @profile_name =  'mail.pacificlawnsprinklers.com',
  @body = @body,
  @body_format ='HTML',
  @recipients = 'MMAHONEY@pacificlawnsprinklers.com', -- replace with your email address
  --@copy_recipients = 'helpdesk@pacificlawnsprinklers.com', 
  @subject = 'Clients in Nassau County with No Water Dept' ;
  
  
   --@attach_query_result_as_file = 0 ;
  end
  </code></pre>