sql server 发送html格式的邮件,参考代码如下:
rush:sql;">
DECLARE @tablehtml NVARCHAR(MAX) ;
-- 获取当前系统时间,和数据统计的时间
set @d_Nowdate = convert(datetime,convert(varchar(10),dateadd(day,-1,getdate()),120),120);
目前测试中
<table border="1">' +
N'<tr>日期 基金代码 基金名称 净值 累计净值 </tr>' +
CAST ( (select convert(varchar(10),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 drq=@dNowdate order by Vc_jjmc,VC_JJDM
FOR XML PATH('tr'),ELEMENTS-- TYPE
) AS NVARCHAR(MAX) ) + N'</table>';
-- 如果有数据则发送
if exists (select top 1 * from t_table1(nolock) where drq=@dNowdate)
begin
set @strsubject='某某'+convert(varchar(10),@dNowdate,120)+'净值.';
SET @tablehtml = N'
某某
目前测试中
<table border="1">' +
N'<tr>
CAST ( (select convert(varchar(10),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 drq=@dNowdate order by Vc_jjmc,VC_JJDM
FOR XML PATH('tr'),ELEMENTS-- TYPE
) AS NVARCHAR(MAX) ) + N'</table>';
-- <a href="https://www.jb51.cc/tag/fasongyoujian/" target="_blank" class="keywords">发送邮件</a>
exec @i_result = msdb.dbo.sp_send_dbmail
@profile_name = 'Profile-Mail',@recipients = '邮箱地址1;邮箱2;邮箱3',@subject = @str_subject,@body = @<a href="https://www.jb51.cc/tag/tablehtml/" target="_blank" class="keywords">tablehtml</a>,@body_format = 'HTML';
end
某某净值
目前测试中
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。