BEGIN
SET @TaskId = (SELECT TOP 1 TaskID FROM WorkTrigger WHERE WorkTriggerName='Scheduled Fees')
IF EXISTS (SELECT 1 FROM Job WHERE tenantid=@TenantId)
BEGIN
PRINT 'Adding the Scheduled Fees Processing'
SET @TenantId = @TenantId + 1
EXEC support.JobInsert @Taskid,'Scheduled Fees Processing', 'SvrScheduledFees',NULL,NULL,@TenantId
END
BEGIN
PRINT 'The Scheduled Fees Processing job already exists'
END
END
GO
the tenant table primary key is not incremental i.e. it starts with 1,31,32,33 ....
i want the script above to insert into job table while getting a next id from the tenant table.
Hi,
Can you please list out the table def from tenant table?
From the above script, since you do not have any insert statement, I don't think you can get SCOPE_IDENTITY() to work.
Given you said that the tenant id is not incremental, but what you trying to do is going to be incremental as you just adding 1 to the next id, you can either use identity field or use sequence. Both should be able to get what you wanted.