DECLARE @SQL_LOG nvarchar(1000) DECLARE @BackupType nvarchar(10) DECLARE @BackupStage nvarchar(20) DECLARE @BackupStatus nvarchar(20) SET @BackupType = @BACKUP_CONTEXT.value('(/Backup/@Type)[1]', 'nvarchar(10)') SET @BackupStage = @BACKUP_CONTEXT.value('(/Backup/@Stage)[1]', 'nvarchar(20)') SET @BackupStatus = @BACKUP_CONTEXT.value('(/Backup/@Status)[1]', 'nvarchar(20)') DECLARE @DatabaseName nvarchar(255) DECLARE crs CURSOR static forward_only read_only FOR SELECT tab.col.value('@Name[1]', 'nvarchar(255)') FROM @BACKUP_CONTEXT.nodes('//Database') tab(col) OPEN crs; FETCH next FROM crs INTO @DatabaseName; WHILE 0 = @@fetch_status BEGIN --- Status: "Finished", "FinishedWithErrors", "Cancelled" or "Failed" IF @BackupType = 'Full' AND @BackupStatus='Finished' AND @DatabaseName LIKE 'PRODUX%' BEGIN SET @SQL_LOG='UPDATE ['+@DatabaseName+'].[dbo].[DB_SETTINGS] SET SYS_DATE_BACKUP_FOOL = GETDATE()' EXEC(@SQL_LOG) END IF @BackupType = 'Diff' AND @BackupStatus='Finished' AND @DatabaseName LIKE 'PRODUX%' BEGIN SET @SQL_LOG='UPDATE ['+@DatabaseName+'].[dbo].[DB_SETTINGS] SET SYS_DATE_BACKUP_DIFF = GETDATE()' EXEC(@SQL_LOG) END FETCH next FROM crs INTO @DatabaseName; END CLOSE crs; DEALLOCATE crs;