How to run sql agent job in ssms every 30 minutes except during a certain time?

mdhar 41 Reputation points
2020-09-09T10:07:33.35+00:00

I have a Sql server agent job which currently runs every 30 minutes, every day, etc.

I'd like to modify it so that it will run every 30 minutes, every day except between 7:00 pm and 11:30 pm. Is this possible with the job scheduler?

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
{count} votes

Answer accepted by question author
  1. Olaf Helper 47,586 Reputation points
    2020-09-09T11:36:20.927+00:00

    Simply test on the current time in the job, like

    IF NOT CONVERT(time, GETDATE()) BETWEEN '19:00:00' AND '23:30:'
    BEGIN
        -- Do the job
        SELECT 1
    END
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,781 Reputation points
    2020-09-09T14:07:59.507+00:00

    Create 2 schedules:
    23493-0-7job.png

    23494-11-12job.png

    0 comments No comments

  2. CathyJi-MSFT 22,406 Reputation points Microsoft External Staff
    2020-09-10T05:59:21.773+00:00

    Hi @MuralidharTangudu-6301,

    As Viorel mentioned, please try this.I test it in my environment, the job works well.

    23733-annotation-2020-09-10-135436.jpg

    Best regards,
    Cathy


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.