根据执行 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否想通过邮件发送查询结果?
无论哪种方式,您都可以执行以下操作:
如果您希望在电子邮件中包含查询结果,那么最简单的方法可能是将它们写入平面文件然后将文件作为附件发送。
或者,使用 sp_send_dbmail 在存储过程中完成整个操作,然后从包中调用该过程。
Do you want to send the results of the query in the mail or not?
Either way, you can do this:
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.
Alternatively, do the whole thing in a stored procedure using sp_send_dbmail and just call the procedure from your package.
它可能有点笨重,但您可以将执行 SQL 任务的结果发送到变量,然后使用基于该变量的 For 循环容器。将发送邮件任务放入该 For 循环容器中。其中的挑战是只运行一次发送邮件,无论计数是 1 还是更多。如果你的计数被保存为布尔值,也许这会起作用?
您可以在两者之间添加另一个步骤,放入一个获取计数并返回 0 或 1 的脚本任务,然后将 For 循环与其中的发送邮件任务结合使用。
就像我说的,笨重。
It's probably a bit clunky, but you could send the results of your Execute SQL task to a variable, then use a For Loop container based on that variable. Put the Send Mail task within that For Loop container. The challange in that is only running the Send Mail once, no matter if the count is 1 or more. If your count was saved as a bool, perhaps that would work?
You could put another step in between, put in a Script Task that takes the count and returns a 0 or 1, and then use the For Loop with the Send Mail task within.
Like I said, clunky.