SQL Server中發(fā)送HTML格式郵件的方法
sql server 發(fā)送html格式的郵件,參考代碼如下:
DECLARE @tableHTML NVARCHAR(MAX) ;
-- 獲取當(dāng)前系統(tǒng)時(shí)間,和數(shù)據(jù)統(tǒng)計(jì)的時(shí)間
set @d_nowdate = convert(datetime,convert(varchar(10),dateadd(day,-1,getdate()),120),120);
-- 如果有數(shù)據(jù)則發(fā)送
if exists (select top 1 * from t_table1(nolock) where d_rq=@d_nowdate)
begin
set @str_subject='某某'+convert(varchar(10),@d_nowdate,120)+'凈值.';
SET @tableHTML = N'<H1>某某</H1><br>目前測(cè)試中<br><table border="1">' +
N'<tr><th>日期</th><th>基金代碼</th><th>基金名稱</th><th>凈值</th><th>累計(jì)凈值</th></tr>' +
CAST ( (select convert(varchar(10),@d_nowdate,120) as 'td','',VC_JJDM as 'td','',Vc_jjmc as 'td','',EN_JJDWJZ as 'td','',EN_LJJZ as 'td'
from t_table1 t left join t_table2 tt on t.VC_JJDM = tt.C_FUNDCODE
where d_rq=@d_nowdate order by Vc_jjmc,VC_JJDM
FOR XML PATH('tr'), ELEMENTS-- TYPE
) AS NVARCHAR(MAX) ) + N'</table>';
-- 發(fā)送郵件
exec @i_result = msdb.dbo.sp_send_dbmail
@profile_name = 'Profile-Mail',
@recipients = '郵箱地址1;郵箱2;郵箱3',
@subject = @str_subject,
@body = @tableHTML,
@body_format = 'HTML';
end
郵件效果如下:
某某凈值
目前測(cè)試中
|
日期 |
基金代碼 |
基金名稱 |
凈值 |
累計(jì)凈值 |
|
2013-12-20 |
111111 |
AAAAA |
0.98300000 |
0.98300000 |
|
2013-12-20 |
222222 |
BBBBB |
1.04900000 |
1.04900000 |
|
2013-12-20 |
333333 |
CCCCC |
0.64000000 |
0.64000000 |
|
2013-12-20 |
444444 |
DDDDD |
0.99400000 |
0.99400000 |
|
2013-12-20 |
555555 |
EEEEE |
1.05700000 |
1.05700000 |
|
2013-12-20 |
666666 |
FFFFF |
0.73400000 |
0.73400000 |
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信