August 21, 2013 at 4:44 am
Hi everyone.
Hope someone can offers some guidance.
Have a requirement to send the contents of a table via email to a location on a set schedule.
What is best way to approach this ?
If anyone has any recommendations on the best way to set this up , please let me know.
For example should I copy contents to a separate table, or extract from current table and email from there ?
thank you.
August 21, 2013 at 4:48 am
Take a look at the "sp_send_dbmail" stored procedure and make use of the @query parameter.
http://technet.microsoft.com/en-us/library/ms190307(v=sql.100).aspx
August 21, 2013 at 4:52 am
To sent the results on a schedule, you can create a SQL Agent job and execute the sp_send_dbmail from a job step.
Most of the time it is no problem to query the table directly. To put the results in a temporary table first would be a waist of resources.
August 21, 2013 at 5:33 am
Perfect thank you.
I have the mail profile etc all working.
Do you know how I would generate the output as a .csv and not a .txt ?
August 21, 2013 at 5:41 am
Use the result_seperator option:
exec sp_send_dbmail
...
@query_attachment_filename = 'sample.csv',
@query_result_separator = ',',
...
August 21, 2013 at 6:17 am
Once again , perfect thank you.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply