title: Getting SQL Database Mail to Format HTML Table with 2 Columns
body: <p>I'm using SQL Server 2005 and am sending a Database Mail formatted in HTML. I am getting the results I need, but I'm having difficulty formatting the table the way I want it. </p>
  
  <p>There are two separate SELECT statements being run that populate the table rows. The problem is that I want them to display side by side as they are in relation to each other, but they will only display one on top of the other. I have tried putting them into two tables within a larger table but it will not shift it over. I haven't used HTML in about 10 years so it's probably a problem with that more than the script itself.</p>
  
  <p>Here is the @body section that contains the two select statements:</p>
  
  <pre><code>    N'&lt;table border="1" cellpadding="0" cellspacing="0"&gt;&lt;font face="arial"&gt;' +
      N'&lt;th&gt;Store Number&lt;/th&gt;' +
      N'&lt;td&gt;'+ CAST ( ( SELECT store_num
                FROM store_results 
                WHERE successful = 'N'
                  OR successful IS NULL 
                ORDER BY store_num ASC FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) )+'&lt;/td&gt;'+
      N'&lt;/td&gt;' +
      N'&lt;td&gt;&lt;table border="1" cellpadding="0" cellspacing="0"&gt;&lt;font face="arial"&gt;' +
      N'&lt;th&gt;Reason&lt;/th&gt;' +
      N'&lt;td&gt;'+CAST ( ( SELECT 
                  CASE successful
                  WHEN 'N' THEN 'Failed'              
                      ELSE 'Did Not Run'
                  END
              FROM store_results where successful = 'N' OR successful is null
              ORDER BY store_num ASC FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) )+'&lt;/td&gt;'+
      N'&lt;/td&gt;' +
      N'&lt;/table&gt;
  </code></pre>