title: Aliasing rows with hyperlinks when sending HTML table via sp_send_dbmail
body: <p>I am emailing an HTML table to users but I want to alias the hyperlinks for space reasons. Please have a look on the image.</p>
  
  <p>Here is the <code>Sample1</code> of the image:</p>
  
  <p><img src="https://i.stack.imgur.com/xwYrv.png" alt="Sample1"></p>
  
  <p>Please see my below code :</p>
  
  <pre><code>    DECLARE @bodyMsg nvarchar(max)
      DECLARE @subject nvarchar(max)
      DECLARE @tableHTML nvarchar(max)
      SET @subject = 'Query Results in HTML with CSS'
      DECLARE @email_to_notify nvarchar(256);
      SELECT @email_to_notify = 'bens@ioec.co.za' ;
      SET @tableHTML = 
      N'&lt;style type="text/css"&gt;
  ...
  &lt;/tr&gt;' +
  CAST ( ( 
  
  SELECT 
  td = y.Customer,'',
  td = y.ContractNumber,'',
  td = y.Description ,'',
  td = y.Market ,'',
  td = y.BDM ,'',
  td = y.EC ,'',
  td = y.Reason ,'',
  td = y.Link 
  FROM (SELECT  FileReference AS 'Reference', Name AS 'Customer' , 
          CASE WHEN ContractNumber IS NULL THEN '' ELSE ContractNumber END AS 'ContractNumber',           
          'http://gateway.ioec.co.za/#/trade/files/' + CONVERT(varchar(10),Gw_File.FileID) AS 'Link'
  FROM Gw_File INNER JOIN ... ) y
  FOR XML PATH('tr'), TYPE 
  ) AS NVARCHAR(MAX) ) +
  N'&lt;/table&gt;' 
  
  EXEC msdb.dbo.sp_send_dbmail @recipients='rajivs@ioec.co.za',
  @subject = @subject,
  @body = @tableHTML,
  @body_format = 'HTML' ;
  </code></pre>
  
  <p>I would also like to highlight rows depending on value of the reason column.</p>