Problem emailing query results with Database mail

  • m getting this error please help ......

    declare @body1 varchar(100)

    set @body1 = 'Server :'+@@servername+ ' My First Database Email '

    EXEC msdb.dbo.sp_send_dbmail @recipients='sam@mail.com',

    @subject = 'teee',

    @body = @body1,

    @body_format = 'HTML',

    @query = 'SELECT message FROM master.dbo.history',

    @attach_query_result_as_file = 1 ;

    Msg 22050, Level 16, State 1, Line 0

    Error formatting query, probably invalid parameters

    Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 495

    Query execution failed: ?Msg 15404, Level 16, State 19, Server absz, Line 1

    Could not obtain information about Windows NT group/user '3434', error code 0x5.

  • SSC-Addicted

    I had the same issue when i was used db mail... after several hours i came across a post that said switch your query around a bit ?

    basically i had to put the select parameter after the attach parameter

    ie...

    @attach_query_result_as_file = 1,

    @query = 'SELECT

    so now i have

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'views',

    @recipients = Me@me.gov.uk',

    @body = 'The Attached file contains details from Non Residential Fires in the last 24 hours',

    @subject = 'Non Residential Fires',

    @execute_query_database = 'BDU-NYFRAviewsCrossQuery',

    @body_format = 'HTML',

    @importance ='High',

    @query_attachment_filename = 'NresFires.txt',

    @attach_query_result_as_file = 1,

    @query = 'SELECT and so on

    After tearing my hair out for hours this simple twist worked great

    Steve

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply