我运行了以下T-SQL作业 - 我需要将发票和信用票据提取到一封电子邮件中 - 但是,在两个单独的表中:
DECLARE @bodyMsg nvarchar(max)
DECLARE @subject nvarchar(max)
DECLARE @tableHTML nvarchar(max)
DECLARE @tableHTML2 nvarchar(max)
SET @subject = 'Invoices & Credits in Past Week'
SET @tableHTML =
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;
border-spacing: 10px;
}
#box-table th
{
font-size: 13px;
font-weight: normal;
background: #b9c9fe;
border-right: 2px solid #9baff1;
border-left: 2px solid #9baff1;
border-bottom: 2px solid #9baff1;
color: #039;
border-spacing: 10px;
padding: 15px;
}
#box-table td
{
border-right: 1px solid #aabcfe;
border-left: 1px solid #aabcfe;
border-bottom: 1px solid #aabcfe;
color: #669;
border-spacing: 10px;
padding: 15px;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>'+
N'<H3><font color="Red">Invoices from Past week</H3>' +
N'<table id="box-table" >' +
N'<tr>
<th>Invoice #</th>
<th>Date</th>
<th>Account #</th>
<th>Customer</th>
<th>ex GST</th>
</tr>' +
CAST ( (
SELECT
td = OINV.DocNum ,'',
td =CONVERT(VARCHAR(8), OINV.DocDate, 3) ,'',
td = OINV.CardCode ,'',
td = OINV.CardName ,'',
td = '$' + CONVERT(varchar, CONVERT(money, OINV.DocTotal-OINV.VatSum-OINV.TotalExpns), 1)
FROM OINV INNER JOIN OSLP ON OINV.SlpCode = OSLP.SlpCode
WHERE OSLP.SlpName = 'SALES REP' and OINV.DocDate > DATEADD(DAY, -7, GETDATE())
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) )
@tableHTML2 =
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;
border-spacing: 10px;
}
#box-table th
{
font-size: 13px;
font-weight: normal;
background: #b9c9fe;
border-right: 2px solid #9baff1;
border-left: 2px solid #9baff1;
border-bottom: 2px solid #9baff1;
color: #039;
border-spacing: 10px;
padding: 15px;
}
#box-table td
{
border-right: 1px solid #aabcfe;
border-left: 1px solid #aabcfe;
border-bottom: 1px solid #aabcfe;
color: #669;
border-spacing: 10px;
padding: 15px;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>'+
N'<H3><font color="Red">Credits from Past week</H3>' +
N'<table id="box-table" >' +
N'<tr>
<th>Credit #</th>
<th>Date</th>
<th>Account #</th>
<th>Customer</th>
<th>ex GST</th>
</tr>' +
CAST ( (
SELECT
td = ORIN.DocNum ,'',
td =CONVERT(VARCHAR(8), ORIN.DocDate, 3) ,'',
td = ORIN.CardCode ,'',
td = ORIN.CardName ,'',
td = '$' + CONVERT(varchar, CONVERT(money, ORIN.DocTotal-ORIN.VatSum-ORIN.TotalExpns), 1)
FROM ORIN INNER JOIN OSLP ON ORIN.SlpCode = OSLP.SlpCode
WHERE OSLP.SlpName = 'SALES REP' and ORIN.DocDate > DATEADD(DAY, -7, GETDATE())
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>'
EXEC msdb.dbo.sp_send_dbmail @recipients='email@email.com',
@profile_name = 'SQL Alerts',
@subject = @subject,
@body = @tableHTML,
@body = @tableHTML2,
@body_format = 'HTML' ;
当我在查询中只有@tableHTML时,会运行此T-SQL脚本。
我需要找出上述错误的原因? 任何帮助表示赞赏!
此致 瑞克