-- BI EMAIL declare @CC varchar(10),@MAIL varchar(500), @str varchar(800),@year varchar(4),@month varchar(2);declare @file_name varchar(50);declare @m ...
-- 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='[email protected]';
begin set @htmlBody=
N'<H1 style="margin-left:30px; "><a href="http://msbi.dcec.com.cn/pbreports"><font size="4">TOP 10 ETL數據倉庫抽取錯誤日誌(點擊查看明細)</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='數據倉庫載入數據ETL任務失敗';
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