Note that there are some explanatory texts on larger screens.

plurals
  1. POsp_send_dbmail - formatting row in table as red for an alert
    primarykey
    data
    text
    <p>I'm using something similar to example C on this MSDN page: <a href="http://msdn.microsoft.com/en-us/library/ms190307.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190307.aspx</a> </p> <pre><code>DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'&lt;H1&gt;Work Order Report&lt;/H1&gt;' + N'&lt;table border="1"&gt;' + N'&lt;tr&gt;&lt;th&gt;Work Order ID&lt;/th&gt;&lt;th&gt;Product ID&lt;/th&gt;' + N'&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Order Qty&lt;/th&gt;&lt;th&gt;Due Date&lt;/th&gt;' + N'&lt;th&gt;Expected Revenue&lt;/th&gt;&lt;/tr&gt;' + CAST ( ( SELECT td = wo.WorkOrderID, '', td = p.ProductID, '', td = p.Name, '', td = wo.OrderQty, '', td = wo.DueDate, '', td = (p.ListPrice - p.StandardCost) * wo.OrderQty FROM AdventureWorks.Production.WorkOrder as wo JOIN AdventureWorks.Production.Product AS p ON wo.ProductID = p.ProductID WHERE DueDate &gt; '2004-04-30' AND DATEDIFF(dd, '2004-04-30', DueDate) &lt; 2 ORDER BY DueDate ASC, (p.ListPrice - p.StandardCost) * wo.OrderQty DESC FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'&lt;/table&gt;' ; EXEC msdb.dbo.sp_send_dbmail @recipients='danw@Adventure-Works.com', @subject = 'Work Order List', @body = @tableHTML, @body_format = 'HTML' ; </code></pre> <p>I have a column called Rating that is set to 'Good' or 'Bad' according to my own logic. I would like to make all lines that have a rating of 'Bad' have a red background. I know how to do it in HTML, but not sure how to do it with the "FOR XML" query being demonstrated in this example. Seems like I would have to add an attribute to some TD statements, and not others. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload