我正在使用SQL + HTML脚本发送包含表mytable
列的电子邮件。该表只有3行。第三行是前两行的差异,因此我想突出显示它(带有一些背景颜色)。我偶然遇到nth-child()
选择器,但不管怎么说,它在我的情况下不起作用。
SET @tableHTML =
N'<style type="text/css">
#box-table
{
font-family: "Arial", "Lucida Grande", Sans-Serif;
text-align: center;
border-collapse: collapse;
}
#box-table th
{
font-size: 13px;
font-weight: bold;
background: #007336;
border: 1px solid #000000;
color: #FFFFFF;
padding-left:5px;padding-right:5px;padding-top:2px;padding-bottom:2px;
}
#box-table td
{
font-size: 12px;
border: 1px solid #000000;
color: #000000;
padding-left:5px;padding-right:5px;padding-top:2px;padding-bottom:2px;
}
</style>'+
----------Overview
N'<table id="box-table" >' +
N'<tr><th>Order Date</th>
<th>System</th>
<th>SKU Count</th>
<th>OUTL $</th>
<th>OH $</th>
</tr>' +
CAST ( (
SELECT td = Order_date,'',
td = System,'',
"td/@align" = 'right', td = SKU_Count,'',
"td/@align" = 'right', td = OUTL_$,'',
"td/@align" = 'right', td = OH_$
FROM #mytable
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table><br/>'
EXEC msdb.dbo.sp_send_dbmail
@recipients='abc@abc.com',
@subject = NULL,
@body = @tableHTML,
@body_format = 'HTML' ;