From: Don Juan on
Hi all

What is the best way in order to send an SQL query via e-mail?
What can I do in sql server side? or programatically? (VB or C#)

Thanks in advanced.
dj
From: Plamen Ratchev on
Assuming you mean the query results, you can use the system stored procedure
sp_send_dbmail using the @query parameter. Here is example:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyProfile',
@recipients = 'foo(a)test.com',
@query = 'SELECT col1 FROM Foo' ,
@subject = 'Query results',
@attach_query_result_as_file = 1 ;

HTH,

Plamen Ratchev
http://www.SQLStudio.com


From: Don Juan on
Thanks!

"Plamen Ratchev" <Plamen(a)SQLStudio.com> wrote in message
news:52F0D1A7-5805-48B4-89E2-A59DE7BCA005(a)microsoft.com...
> Assuming you mean the query results, you can use the system stored
> procedure sp_send_dbmail using the @query parameter. Here is example:
>
> EXEC msdb.dbo.sp_send_dbmail
> @profile_name = 'MyProfile',
> @recipients = 'foo(a)test.com',
> @query = 'SELECT col1 FROM Foo' ,
> @subject = 'Query results',
> @attach_query_result_as_file = 1 ;
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com
>
>