December 1, 2016 at 11:07 am
How do you Output the Results of T-SQL Query to an e-mail attachment and/ or Body?
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
December 1, 2016 at 12:02 pm
the obvious answer would be sp_send_dbmail:
https://msdn.microsoft.com/en-us/library/ms190307.aspx
I prefer to use the @attach_query_result_as_file=1 option, because the results are often easier to read in the text file than in the body where outlook would spoil the formatting.
is database mail not setup in your environment?
December 1, 2016 at 12:08 pm
If you want to explicitly stay with SSIS tasks though instead of SQL, then you'd have to do a lot of gyrations, including saving the results explicitly to a variable or file, then using the email task/
December 1, 2016 at 12:09 pm
I assume this is from Integration Services? If so, use a data flow to put the query results in a file (with your format of choice) and then use a send mail task (SMTP) to send the file as an attachment.
December 1, 2016 at 1:24 pm
Chris Harshman (12/1/2016)
the obvious answer would be sp_send_dbmail:https://msdn.microsoft.com/en-us/library/ms190307.aspx
I prefer to use the @attach_query_result_as_file=1 option, because the results are often easier to read in the text file than in the body where outlook would spoil the formatting.
is database mail not setup in your environment?
I like your approach.
Thanks.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply