пятница, 16 октября 2015 г.

MS SQL server starting work on the name

The problem arose when MS SQL server, you must restart of need jobs, manually do job I did not like, that's wrote the script
DECLARE @SQL NVARCHAR(MAX)
DECLARE @job SYSNAME

DECLARE jobs_cursor CURSOR
FOR
SELECT 'EXEC msdb.dbo.sp_start_job ''' + s.NAME + ''''
FROM msdb..sysjobs s
WHERE s.NAME LIKE 'Reset%'

OPEN jobs_cursor

FETCH NEXT
FROM jobs_cursor
INTO @job

WHILE @@Fetch_Status = 0
BEGIN
 PRINT @job

 EXEC sp_executesql @job_name = @job

 FETCH NEXT
 FROM jobs_cursor
 INTO @job
END

CLOSE jobs_cursor

DEALLOCATE jobs_cursor
The basic scheme of the script, find need task with begin name 'Reset', then run them.