question

GrumpyDBA2 avatar image
GrumpyDBA2 asked

Can anyone help with a sql script that queries msdb to get failed agent jobs and sends out an email ?

Can anyone help with a sql script that queries msdb to get failed agent jobs and sends out an email ?
sql-agentmsdbsql-email
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ASK SQL Server Central runs by you voting. For all helpful answers below, please indicate this by clicking on the thumbs up next to those answers. If any one answer lead to a solution, please indicate this by clicking on the check mark next that answer.
0 Likes 0 ·
Tim avatar image
Tim answered
You could take the script for this [answer on a similar question]( http://stackoverflow.com/questions/10577676/how-to-obtain-failed-jobs-from-sql-server-agent-through-script) and output to a file when the result has a count > 1, then execute database mail to send you the email with attachment of the result, or get creative and if count > 1 send the results in the body of the email rather than attachment.
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Wilfred van Dijk avatar image
Wilfred van Dijk answered
This option is already included in every job. Make sure you have database mail and operators up and running. For every job you want to notify in case of a failure: - right click on the job - go to tab 'Notifications' - enable 'Email'. - Select the operator to notify and make a decision when you want to be notified (always/on success/on error)
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.