SQL DBA – Stop multiple running SQL Jobs at once
Just like my previous post on Enable/Disable multiple SQL Jobs [link], here I will show how can we stop multiple jobs running by SQL Agent at once.
–> Although you can very well Stop a SQL Job in SSMS by simple right-clicking on it. But if you have multiple SQL Jobs running, to stop each of them will be a cumbersome and time taking task.
I will show how this can be done by a T-SQL query:
USE msdb; GO -- Stop Multiple running SQL Jobs at once: DECLARE @dynSql NVARCHAR(MAX) = '' SELECT @dynSql += N' msdb.dbo.sp_stop_job @job_name = ''' + j.name + N'''' + CHAR(10) + CHAR(13) FROM msdb.dbo.sysjobs j JOIN msdb.dbo.sysjobactivity AS ja ON ja.job_id = j.job_id WHERE ja.start_execution_date IS NOT NULL AND ja.stop_execution_date IS NULL ORDER BY j.name; PRINT @dynSql; GO
Simply Copy-Paste the the above Dynamically generated SQL Script and Execute it, it will Stop all Running SQL Jobs at once.
Thanks alot Manoj…Searching this script from many days..finally got it..once again thanks alot
It will create a list of jobs that are to be stopped, but does not stop the jobs. Its needs the EXEC command.