Contents
How do I email a query result in SSIS?
- Add a Execute SQL Task. Add query as below SELECT COlumnName FROM logTable.
- Add another execute sql task. Set SQLSourceType as variable and map to above variable @{User::Query].
- Add Send Mail Task.
How do I send records from a table in an email body using SSIS package?
Using SSIS to send emails to a table of people
- Step 1 – Creating the variables needed. The first thing to do is to create two variables:
- Step 2 – read the rows into the object variable. The next step is to read the rows into your ViewRows variable.
- Step 3 – looping over each row.
- Step 4 – sending the email.
How to send SQL query results via email?
One common request is to execute a query and send the results via email on a regular basis. This task is a great match for SQL Server Agent and sp_send_dbmail. Setting up a job and a step that uses sp_send_dbmail with the @query parameter, and building on it with other available parameters, you can easily accomplish this.
Can you send email with results of multiple select statements?
Your first query would execute without any issue but your second query is creating a result set bigger than your settings allow so it will not send, I agree with @kin that you would be better off saving the results down somewhere and then email a link. As a bonus your network administrators will be happier too!
Can a SQL query be attached to an e-mail?
The results of the query can be attached as a file, or included in the body of the e-mail message. The query is of type nvarchar (max), and can contain any valid Transact-SQL statements. Note that the query is executed in a separate session, so local variables in the script calling sp_send_dbmail are not available to the query.
How to send result set from query as an attachment?
/*Microsoft SQL Server Integration Services Script Task Write scripts using Microsoft Visual C# 2008.