Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append sql result to a mail

Status
Not open for further replies.

CliveW

Technical User
Aug 19, 2002
36
0
0
GB
I need to send an email from a select within a stored procedure and that the attachement is appended to the mail. I also need a copy of the file to be placed into a text file on the system.

I can send the result when setting the @attach_result=True
in xp_sendmail

I can also copy the result to disk using xp_cmdshell bcp

What I can't do is pick the file up and send it. Or is there a better way of doing this.
 
Could you store the result in a table on the database and then send it using xp_sendmail with the @query parameter = select * from table
 
You can specify the attachment name and path in the execution of xp_sendmail.

Exec master.dbo.xp_sendmail
@recipients='CliveW@someserver.com',
@subject='Query Results',
@message='The attached file contains the results you requested.',
@query=@sql, --@sql cojntains the query statement
@attach_results='True',
@attachments='E:\SQLMail\QueryResults\FILENAME.txt',
@width=256 Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top