在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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 邮件效果如下: 某某净值 目前测试中
|
请发表评论