Search code examples
sql-serverssissql-server-agentsql-agent-job

Execute a SQL agent job based off a constraint


How do you execute a SQL server agent job in a schedule only if a certain criteria is met. My example is that I only want to run the job if a boolean value on a different server is set to true otherwise it must not run


Solution

  • Schedules are not conditional. They run at the time they are scheduled, no matter what.

    If you want your job to do something only when certain conditions are met, you have to expect that the job will always run on schedule, and put something in the steps that the job executes to check the condition.

    So if your job executes SQL Statements, you would put IF blocks in your SQL. If it executes an SSIS package, you would start the package by checking a condition, and so on.