IF EXISTS(
SELECT * FROM msdb.dbo.sysjobhistory
WHERE UPPER(master.dbo.fn_varbintohexstr(job_id)) = UPPER('$(ESCAPE_SQUOTE(JOBID))')
AND msdb.dbo.agent_datetime(run_date, run_time) >= msdb.dbo.agent_datetime($(ESCAPE_SQUOTE(STRTDT)), $(ESCAPE_SQUOTE(STRTTM)))
AND run_status <> 1
)
BEGIN
  RAISERROR('One or more job steps have failed.',16,1)
END