-- BI EMAIL
declare @CC varchar(10),@MAIL varchar(500), @str varchar(800),@year varchar(4),@month varchar(2); declare @file_name varchar(50); declare @mail_subject varchar(50); declare @htmlBody varchar(max); SELECT @year = CONVERT(VARCHAR(4),DATEPART(year,dateadd(MONTH,-1,GETDATE()))) ; SELECT @month = right('0'+CONVERT(VARCHAR(2),DATEPART(month,dateadd(MONTH,-1,GETDATE()))),2); SELECT @MAIL='BI@163.com.cn'; begin set @htmlBody=
N'<H1 style="margin-left:30px; "><a href="http://msbi./pbreports"><font size="4">TOP 10 ETL數(shù)據(jù)倉庫抽取錯誤日志(點擊查看明細(xì))</font></a></H1>' + N'<table border="1" style="border:1px solid #d5d5d5;border-collapse:collapse;border-spacing:0;margin-left:30px;margin-top:20px;">' + N'<tr style="height:25px;"><th width=60px" >表名</th>'+ N'<th width=50px>包名</th><th width=120px>抽取時間</th>'+ N'<th width=150px>錯誤信息</th>'+ CAST ( ( select td=a.table_name, '',td=a.package_name, '',td=a.process_starttime,'', td=a.error_description, '' from (select top 10 table_name,package_name,process_starttime,error_description from tempdb.dbo.bi_etl_error ) a FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'</table>'; --select @htmlBody; set @mail_subject='數(shù)據(jù)倉庫加載數(shù)據(jù)ETL任務(wù)失敗'; exec msdb.dbo.sp_send_dbmail @profile_name='BIMAIL', @recipients=@MAIL, @subject=@mail_subject, @body=@htmlBody, --@execute_query_database='ReportServer', --@query='select * from dbo.Roles', --@attach_query_result_as_file=1, --@query_attachment_filename=N'a.xlsx' --@file_attachments=@file_name @body_format='HTML'; end |
|