SQL Server中發送HTML格局郵件的辦法。本站提示廣大學習愛好者:(SQL Server中發送HTML格局郵件的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是SQL Server中發送HTML格局郵件的辦法正文
sql server 發送html格局的郵件,參考代碼以下:
DECLARE @tableHTML NVARCHAR(MAX) ; -- 獲得以後體系時光,和數據統計的時光 set @d_nowdate = convert(datetime,convert(varchar(10),dateadd(day,-1,getdate()),120),120); -- 假如稀有據則發送 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>今朝測試中<br><table border="1">' + N'<tr><th>日期</th><th>基金代碼</th><th>基金稱號</th><th>淨值</th><th>累計淨值</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>'; -- 發送郵件 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
郵件後果以下:
某某淨值
今朝測試中
日期
基金代碼
基金稱號
淨值
累計淨值
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