SQL server 2008, I have a table which stored the created Job_id for each job and then for deleting the job I use a stored procedure (below) which gets the ID and tries to delete the job but although I'm sure that the job exists with @ScheduleReportID but the following select always returns null ! Job_id is of type UniqueIdentifier in tbRptSchedule
declare @job_name nvarchar(max)
SELECT @job_name = name
from msdb.dbo.sysjobs with(nolock)
where job_id = (select job_id from dbo.tbRptSchedule with(nolock) where ScheduledReportID = @ScheduledReportID)
IF @job_name IS NULL
BEGIN
RAISERROR ('Cannot find Job identifier',16,1)
END