简体   繁体   English

SQL Server中的电子邮件通知

[英]email notification in sql server

I have a stored procedure which has 2 parameters @LastUpdateDate and @CurrentDate I calculate the difference between these two days and store it in another variable called Sub, like this 我有一个存储过程,该过程具有2个参数@LastUpdateDate@CurrentDate我计算这两天之间的差并将其存储在另一个名为Sub的变量中,如下所示

declare @sub int
select @sub = (datediff(dd,@LastUpdate,@CurrentDate))

If the value of Sub is greater than 0, I want to send an email notification to few people that the cube has not been refreshed since last day. 如果Sub的值大于0,我想向少数人发送一封电子邮件通知,指出自上一天以来未刷新多维数据集。

Can any one tel me how I can achieve this ? 有人可以联系我如何实现这一目标吗? I tried sqldbmail, but that option didn't work 我尝试了sqldbmail,但是该选项不起作用

I'm not sure about sqldbmail. 我不确定sqldbmail。 The standard would be to use sp_send_dbmail . 标准是使用sp_send_dbmail

It requires some set up which is discussed in the accepted answer to How to send email from SQL Server? 它需要一些设置,有关如何从SQL Server发送电子邮件的可接受答案中对此进行了讨论 as Leo commented. 正如利奥所说。

Personally I'm a fan of [ab]using SQL Agent for this - assuming that this is a scheduled check and I'm only contacting SQL-admin-bods... 我个人是[ab]使用SQL Agent的支持者-假设这是计划的检查,而我仅与SQL-admin-bods联系...

I would set up a job with a single T-SQL step with code along the lines of: 我将通过一个T-SQL步骤并通过以下代码编写代码来建立工作:

EXEC your_sproc 'etc', 'etc';

IF DateDiff(dd, @LastUpdate, @CurrentDate) > 0
  BEGIN
    RAISERROR ('Cube not refreshed', 18, 1);
  END
;

Then I would set a notification email when the job fails 然后我会在工作失败时设置通知电子邮件

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM