ALTER procedure [dbo].[monitorJob]
@name varchar(100)
as
begin
declare @bd varchar(100) ;
if exists(
select * from msdb.dbo.sysjobhistory
where job_id in (select job_id from msdb.dbo.sysjobs where [name]=@name )
and run_date=convert(varchar,getdate(),112)
and run_status=0)
begin
set @bd=‘10.158.32.154 计划任务 ‘+@name+‘ 执行失败!‘
exec MaganerDB.dbo.[spSendMail] @from=‘dwchaoyue@163.com‘,
@to=‘v.dengwang@snda.com;lidenggao@snda.com‘,
@bcc=‘‘, -- 抄送
@subject=‘自动化任务失败‘,
@htmlBody=@bd,
@addAttachment=‘‘ -- 附件
end
end
本文出自 “SQLServer MySQL” 博客,请务必保留此出处http://dwchaoyue.blog.51cto.com/2826417/1533924