Can we attach the result produced by query in .txt format in sql?

189 views Asked by At

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

1

There are 1 answers

0
Indranil.Bharambe On

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 protected]', @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/