emailing the query result

  • Hi All,

    I worked a bit with Datbase mail,

    i got job notification when it gets done successfully or failed.

    but now i want to mail the query result to some specific email address

    please let me know how can i do this ??

    can we have it via databasemail or some other task???

  • You can attach the query result in "attach_query_result_as_file " parameter.

    Example from BOL:

    ===================

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'AdventureWorks2008R2 Administrator',

    @recipients = 'danw@Adventure-Works.com',

    @query = 'SELECT COUNT(*) FROM AdventureWorks2008R2.Production.WorkOrder

    WHERE DueDate > ''2006-04-30''

    AND DATEDIFF(dd, ''2006-04-30'', DueDate) < 2' ,

    @subject = 'Work Order Count',

    @attach_query_result_as_file = 1 ;

    "More Green More Oxygen !! Plant a tree today"

  • thanks Minhas , this is exactly what i was looking for 😛

Viewing 3 posts - 1 through 2 (of 2 total)

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