Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Posts
    20

    Unanswered: E-mail query results with Database Mail

    Hello
    Is it possible to e-mail multiple lines from a table by using database mail.
    I have a stored proc that inserts data into a table variable and if there
    is information in the table execute the msdb.dbo.sp_send_dbmail stored proc.
    I am struggling to pass multiple lines to the body of the e-mail.

  2. #2
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Hi HendrikB,

    It is definitely possible to do this. The example below will attach the results as a text file. If you set the @attach_query_result_as_file parameter to 0 the result will be appended to the body of the email.

    EXEC msdb.dbo.sp_send_dbmail

    @recipients=N'joe.bloggs@gmail.com',
    @body='Message Body',

    @subject ='Message Subject',
    @profile_name ='DatabaseMailProfile',
    @query ='SELECT TOP 10 * FROM Northwind.dbo.Products',

    @attach_query_result_as_file = 1,
    @query_attachment_filename ='Results.txt'
    JJ Kennedy
    Double J IT Solutions
    www.doublejit.co.nz

    VB 6, VB.NET, ASP.NET, MS SQL Server, MySQL, MS Access

  3. #3
    Join Date
    Jan 2008
    Posts
    20
    Thank You, got it to work

  4. #4
    Join Date
    Oct 2004
    Posts
    1
    good one thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •