i'd like to list out the failed jobs within the last 24 hrs. if there's none, print "none". however i'm getting an error.
error:
Msg 128, Level 15, State 1, Line 39
The name "none" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
here's what i have:
DECLARE @FinalDate INT;
SET @FinalDate = CONVERT(int
, CONVERT(varchar(10), DATEADD(DAY, -1, GETDATE()), 112)
)
IF EXISTS(SELECT j.[name]
FROM msdb.dbo.sysjobhistory h
INNER JOIN msdb.dbo.sysjobs j
ON h.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps s
ON j.job_id = s.job_id
AND h.step_id = s.step_id
WHERE h.run_status = 0
AND h.run_date > @FinalDate )
begin
SELECT j.[name], h.run_date
FROM msdb.dbo.sysjobhistory h
INNER JOIN msdb.dbo.sysjobs j
ON h.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps s
ON j.job_id = s.job_id
AND h.step_id = s.step_id
WHERE h.run_status = 0
AND h.run_date > @FinalDate
end
else
begin
print "none"
end
replace the double quotes with single quotes
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply