Sql Server变量在存储过程中松散它的值

时间:2021-11-17 10:06:11

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

SQL server 2008,我有一个表,它为每个作业存储创建的Job_id,然后删除作业我使用存储过程(下面)获取ID并尝试删除作业但是我确信作业存在使用@ScheduleReportID,但以下select始终返回null! Job_id在tbRptSchedule中的类型为UniqueIdentifier

    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

1 个解决方案

#1


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).

也许声明@jobname nvarchar(max)与错误有关,因为这里sysname相当于NOT NULL varchar(128)。

#1


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).

也许声明@jobname nvarchar(max)与错误有关,因为这里sysname相当于NOT NULL varchar(128)。