我的IF语句是存储过程的一部分,如下所示:
BEGIN TRY
IF EXISTS (SELECT which I have confirmed returns no results, has a variable called from another table in the where clause)
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = @dynamic_profile,
@recipients = @dynamic_recipient,
@subject = @subjectline,
@body = @mailHTML,
@body_format = 'HTML';
END
END TRY
这与每15分钟运行一次的工作有关。 为什么在IF语句要求跳过邮件发送时,如果select没有返回结果,它会不断发送空白电子邮件?
我的NOCOUNT设为开启
答案 0 :(得分:2)
尝试 - 改为:
IF (SELECT COUNT(*) FROM whatever) > 0
BEGIN
--MAIL
END