-2

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
Asha
  • 3,871
  • 7
  • 44
  • 57

1 Answers1

0

Maybe the declare @jobname nvarchar(max) has something to do with the error as here and here sysname is equivalent to a NOT NULL varchar(128).

Community
  • 1
  • 1
Yaroslav
  • 6,476
  • 10
  • 48
  • 89