Email a CSV result file

Last Post 22 Aug 2008 06:17 AM by SQLUSA. 1 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
New Member
New Member

20 Aug 2008 04:47 AM
I know you can email sql statements to an email but does anyone know how to ..

1. Get a results set as CSV.
2. Attach/Send that CSV to an email address. (at the end of a stored procedure)

Thanks for you help !

New Member
New Member

22 Aug 2008 06:17 AM

You can do the following:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Support'
,@recipients =
,@subject = 'Daily Transaction Summary'
,@attach_query_result_as_file = 1

In the select query, you put it out as a line, e.g. varchar(100), and you format with the commas to achieve the desired output.

Let us know if helpful.

Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQL Server Training, SSAS, SSIS, SSRS:

Acceptable Use Policy