如果SQL 2016中的列为NULL,则安排SQL作业发送电子邮件警报?

时间:2017-09-25 23:35:21

标签: jobs sql-server-2016 sql-server-agent

如何在SQL服务器中安排作业,当SQL作业发送电子邮件警报时,如果列'卷'在表'表1'是NULL吗?

1 个答案:

答案 0 :(得分:0)

设置好Database Mail Profile后,您可以根据需要创建一个按照合适的时间表执行SQL Agent Job的预定sp_send_dbmail

例如:

declare @NullCheck nvarchar(100);
set @NullCheck = (select YourColumn from YouTable);

if @NullCheck is null
execute msdb.dbo.sp_send_dbmail @profile_name = 'YourDBMailProfileName'
                               ,@recipients = 'YourEmail@Example.com'
                               ,@subject = 'Column is NULL'
                               ,@body = 'The Column is currently NULL'