Email a CSV result file

Last Post 22 Aug 2008 07:17 AM by SQLUSA. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ckim472
New Member
New Member

--
20 Aug 2008 05: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 !

Charles
SQLUSA
New Member
New Member

--
22 Aug 2008 07:17 AM
Charles,

You can do the following:



EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Support'
,@recipients = marys@abccorp.com
,@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: http://www.sqlusa.com/
You are not authorized to post a reply.

Acceptable Use Policy