根据执行 SQL 任务的输出发送邮件任务 [英] Send Mail Task based on output from Execute SQL Task

查看:32
本文介绍了根据执行 SQL 任务的输出发送邮件任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据 SSIS 中执行 SQL 任务的输出发送电子邮件?如果查询返回任何结果,我想发送电子邮件,否则不应发送电子邮件.

How to send an email based on the ouput from the execute SQL Task in SSIS? If the query returns any results I would like to send an email if not the email should not be sent.

推荐答案

是否要在邮件中发送查询结果?

Do you want to send the results of the query in the mail or not?

无论哪种方式,您都可以这样做:

Either way, you can do this:

  1. 捕获您的返回的行数在变量中查询
  2. 在优先约束中使用表达式 仅当行数大于零时才发送电子邮件
  1. Capture the number of rows returned by your query in a variable
  2. Use an expression in your precedence constraint to send the email only if the rowcount was greater than zero

如果您希望在电子邮件中获得查询结果,那么最简单的方法可能是将它们写入一个平面文件,然后将该文件作为附件发送.

If you want the results of the query in the email, then the simplest thing is probably to write them to a flat file and then send the file as an attachment.

或者,使用 sp_send_dbmail 在存储过程中完成整个过程,然后从包中调用该过程.

Alternatively, do the whole thing in a stored procedure using sp_send_dbmail and just call the procedure from your package.

这篇关于根据执行 SQL 任务的输出发送邮件任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆