title: SQL HTML Email Column Format instead of row format
body: <p>I'm trying to figure out how to flip this from a table format to a column format. </p>
  
  <p>Hi, I know how to create a SQL HTML Email via table format: i.e</p>
  
  <pre><code>Customer        Address     City
  Joe             123 Here     Oakland 
  </code></pre>
  
  <p>but i need to be able to flip this to look like</p>
  
  <pre><code>Customer:   Joe
  Address:    123 Here
  City:       Oakland
  </code></pre>
  
  <p>I'm using SQL 2012 </p>
  
  <p>Any help would be appreciated </p>
  
  <p>Please advise</p>
  
  <pre><code>DECLARE @xmlinv NVARCHAR(MAX);
  DECLARE @bodyinv NVARCHAR(MAX);
  DECLARE @trrowinv NVARCHAR(MAX);
  DECLARE @tempemaillistinv NVARCHAR(MAX);
  DECLARE @subject_anomaly NVARCHAR(MAX);
  SET @subject_anomaly
      = N'Inventory Adjustments ' + CAST(@COUNTSinv AS VARCHAR(3)) + N' '
        + LEFT(CONVERT(VARCHAR(10), GETDATE(), 101), 3) + SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 101), 4, 3)
        + RIGHT(CONVERT(VARCHAR(10), GETDATE(), 101), 2);
  SET @xmlinv
      = CAST(
        (
            SELECT T4.product AS 'td',
                   '',
                   T4.available AS 'td',
                   '',
                   CASE
                       WHEN T4.quarantine IS NULL THEN
                           0
                       ELSE
                           T4.quarantine
                   END AS 'td',
                   '',
                   CASE
                       WHEN T4.labels IS NULL THEN
                           0
                       ELSE
                           T4.labels
                   END AS 'td',
                   '',
                   T4.MinLog AS 'td',
                   '',
                   T.available AS 'td',
                   '',
                   CASE
                       WHEN T.quarantine IS NULL THEN
                           0
                       ELSE
                           T.quarantine
                   END AS 'td',
                   '',
                   CASE
                       WHEN T.labels IS NULL THEN
                           0
                       ELSE
                           T.labels
                   END AS 'td',
                   '',
                   T.MinLog AS 'td'
            --SELECT T4.product,T4.available,T4.quarantine,T4.labels,T4.MinLog,T.available,T.quarantine,T.labels,T.MinLog 
            FROM #t4 AS T4
                LEFT OUTER JOIN #t3 AS T3
                    ON T4.MaxRow2 = T3.MaxRow
                       AND T4.product = T3.product
                LEFT OUTER JOIN #t2 AS T2
                    ON T4.MaxRow2 = T2.MaxRow
                       AND T4.product = T2.product
                LEFT OUTER JOIN #temp AS T
                    ON T4.MaxRow2 = T.therow + 1
                       AND T4.product = T.product
            ORDER BY 1
            --ORDER BY 1,3 desc
            FOR XML PATH('tr'), ELEMENTS
        )
  AS
  NVARCHAR(MAX));
  
  SET @bodyinv
      = N'&lt;html&gt;&lt;H2&gt;Adjustments&lt;/H2&gt;&lt;body bgcolor=white&gt;&lt;table border=1  style=''border:1px;background-color:#FFFFCC;bordercolor:#FFCC00'' cellpadding=''1'' cellspacing=''0''&gt;';
  SET @trrowinv
      = N'&lt;tr&gt;&lt;th&gt;Product&lt;/th&gt;&lt;th&gt;NewAvailable&lt;/th&gt;&lt;th&gt;NewQuarantine&lt;/th&gt;&lt;th&gt;NewLabels&lt;/th&gt;&lt;th&gt;LastUpdate&lt;/th&gt;&lt;th&gt;OldAvailable&lt;/th&gt;&lt;th&gt;OldQuarantine&lt;/th&gt;&lt;th&gt;OldLabels&lt;/th&gt;&lt;th&gt;PriorUpdate&lt;/th&gt;&lt;/tr&gt;';
  SET @bodyinv = @bodyinv + @trrowinv + @xmlinv + N'&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;';
  
  SET @tempemaillistinv = N'abc@abc.com';
  EXEC [msdb].[dbo].[sp_send_dbmail] @recipients = @tempemaillistinv,
                                     @body = @bodyinv,
                                     @body_format = 'HTML',
                                     @subject = @subject_anomaly,
                                     @profile_name = 'abc';
  </code></pre>