Query for generate the email message which SQL job got executed or not

Query for generate the email message which SQL job got executed or not

Environment: 

iVend 6.6 integrated with SAPB1


Problem Statement:

Query for generate the email message which SQL job got executed or not


Symptoms: 

NA


Resolution/Work Around:

We can use below query to send email message which SQL job got executed or not


declare @lFailedJobCount int

set @lFailedJobCount = 0

select MAX(run_date), (case sh.run_status

when 0 then 'Failed'

when 1 then 'Succeeded'

when 2 then 'Retry'

when 3 then 'Canceled'

when 4 then 'In progress'

end) as RunStatus, j.name

from msdb.dbo.sysjobs j , msdb.dbo.sysjobhistory sh

where sh.job_id = j.job_id

and sh.step_id = 0

group by j.name, run_status

having sh.run_status = 0

select @lFailedJobCount =@@ROWCOUNT

if @lFailedJobCount > 0

BEGIN

EXEC msdb.dbo.sp_send_dbmail

@profile_name = 'IT Support',

-- Give recipient email address

@recipients = 'abc@citixsys.com',

@body = 'SQL Job Status: ',

@query = 'select MAX(run_date), (case sh.run_status

when 0 then ''Failed''

when 1 then ''Succeeded''

when 2 then ''Retry''

when 3 then ''Canceled''

when 4 then ''In progress''

end) as RunStatus, j.name

from msdb.dbo.sysjobs j , msdb.dbo.sysjobhistory sh

where sh.job_id = j.job_id

and sh.step_id = 0

group by j.name, run_status;',

@subject = 'Issue in running sql jobs!',

@execute_query_database = 'master';

END

 

Recommendations /Suggestion: 

NA


    • Related Articles

    • Email showing error message through schedule "Failure sending mail"

      Environment: iVend Version 6.6 with SAPB1 10 Problem Statement: Email showing error message through schedule "Failure sending mail" Symptoms: Email showing error message through schedule "Failure sending mail". The error is displayed in schedule log ...
    • iVend 6.6 Performance Issues-Required SQL Index

      This KM is for Internal Purpose Only for CitiXsys Environment: iVend 6.6 Problem Statement: We have noticed that customers are facing performance issues with iVend 6.6. Symptoms: Environment Specific Resolution/Work Around: Technical Team has checked ...
    • Virus attack or iVend Enterprise database got crashed due to any reason.

      ****** Internal to CitiXsys****** If any of SAPB1 and iVend Enterprise database got crashed due to any reason,we will suggest you to re-initialize the iVend with SAPB1 again as newly initialization actvitiy. It is because there is another database ...
    • SQL query to disable "Use Inter-Store Transactions"

      ************************************ INTERNAL ********************************************************* Consult Support Manager/Technical manager before using this query Below Queries is Only for 6.5 Update x 1. STOP Replication at HO. 2. Take Backup ...
    • SQL Queries : iVend Enterprise /HO database Purge

      ****************INTERNAL TO SUPPORT TEAM ( Not for Customers) ************************* Note:-This article is created only for Support team and will be done along with product expert. Environment: iVend 6.6 integrated with SAPB1 Problem Statement: ...