0

Is it possible to attach the result produced by query in .txt format while sending mail in sql ?

viji
  • 119
  • 2
  • 3
  • 12

1 Answers1

0

One way is to use the extended stored procedure xp_sendmail. It does require that you have a MAPI profile and SQL Mail configured. Then it can be used like this:

xp_sendmail @recipients = 'email@domain.com', @subject = 'Query Results', @query = 'SELECT fname, lname FROM Employees WHERE empid = 9'

In the above example the results of the query will be included in the e-mail message. Read in SQL Server Books OnLine more about the additional parameters for xp_sendmail. They control how the query is executed (database context, database user) and how it is displayed (headers, formatting, attach query results in a file).

Here is more info on configuring SQL Mail: http://support.microsoft.com/kb/q263556/

Indranil.Bharambe
  • 1,462
  • 3
  • 14
  • 25