Stopping Job if running on particular time

  • Hi Experts,

    We have maintenance jobs running on all servers on weekends .Is there anyway i can stop these jobs if these jobs still run on monday morning.

    Thanks in Advance

  • You can schedule a job that runs Monday morning at a certain time and runs the following:

    You can use this query to get a list of the currently executing job names:

    SELECT [sjv].[name]

    FROM [msdb].[dbo].[sysjobs_view] sjv

    JOIN [msdb].[dbo].[sysjobactivity] sja ON [sjv].[job_id] = [sja].[job_id]

    WHERE [sja].[run_requested_date] IS NOT NULL

    AND [sja].[stop_execution_date] IS NULL

    --AND sjv.name LIKE '%YourMaintJobName(s)Here%'

    Then pass the job names through sp_stop_job:

    EXEC msdb.dbo.sp_stop_job @jobname

    Twitter: @SQL_JGood
    Blog: sqljgood.wordpress.com/[/url]

  • Thanks a lot J.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply