我正在尝试在sp_send_dbmail中使用HTML格式,该表有2个彼此相邻的表。我必须为我的每组数据设置一个表格,并且我不希望电子邮件变长,因为每个表格在电子邮件中逐一显示。这是我目前的情况。任何帮助将不胜感激。
更新:我制作了第二张表格,其中包含第一张表格的信息。但是当我运行它时,整个表只包含CurrentInventoryByLocation表中的代码。我错过了什么?
Select @CurrentInventoryByLocation =
N'<style type="text/css">
#box-table
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
text-align: center;
border-collapse: collapse;
border-top: 7px solid #9baff1;
border-bottom: 7px solid #9baff1;
}
#box-table th
{
font-size: 13px;
font-weight: Bold;
background: #b9c9fe;
border-right: 2px solid #9baff1;
border-left: 2px solid #9baff1;
border-bottom: 2px solid #9baff1;
color: #039;
}
#box-table td
{
border-right: 1px solid #aabcfe;
border-left: 1px solid #aabcfe;
border-bottom: 1px solid #aabcfe;
color: #669;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>'+
N'<H4><font color="Black">By Location</H4>'+
N'<table id="box-table">'+
N'<tr><font color = "Black">
<th> Location </th>
<th> Current Inventory Value </th>
<th> Current Inventory Tons </th>
</tr>'
+ CAST ( (
select
TD = LOCATION,'',
TD = left(convert(CHAR(17),cast(CURRENT_INVENTORY_VALUE as money),1),14),'',
TD = left(convert(CHAR(17),cast(CURRENT_INVENTORY_TONS as money),1),14)
from Current_Inventory_ByLocation_CTE order by current_inventory_value desc
FOR XML PATH ('tr')
) as varchar(max))
+ '</table>'
Select @OverallTable =
N'<style type="text/css">
#box-table
{
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 12px;
text-align: center;
border-collapse: collapse;
border-top: 7px solid #9baff1;
border-bottom: 7px solid #9baff1;
}
#box-table th
{
font-size: 13px;
font-weight: Bold;
background: #b9c9fe;
border-right: 2px solid #9baff1;
border-left: 2px solid #9baff1;
border-bottom: 2px solid #9baff1;
color: #039;
}
#box-table td
{
border-right: 1px solid #aabcfe;
border-left: 1px solid #aabcfe;
border-bottom: 1px solid #aabcfe;
color: #669;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>'+
N'<H4><font color="Black">Test</H4>'+
N'<table id="box-table">'+
N'<tr><font color = "Black">
<th> Location </th>
<th> Current Inventory Value </th>
<th> Current Inventory Tons </th>
</tr>'
+ CAST ( (
Select
TD = @CurrentInventoryByLocation
FOR XML PATH ('tr')
) as varchar(max))
+ '</table>'