Daisy chain SQL Jobs based on condition

  • Hi, Let me better explain. My first job executes every 15 minutes (top of the hour, 12:15, 12:30 and 12:45). It does this for every day of the week.

    I have a second job that runs at 1:30 AM on the first day of the month. This job only runs once a month.

    I need to daisy chain job one with job two only on the last execution of a given month. Meaning, job one executes at 11:45 pm and executes for 3 hours, at that point I need job two to start.

    Thanks in advance.

    RC

  • I'd put a new step in job one. Write logic in that step that only calls sp_Startjob for job 2 on the first of the month.

  • excuse my ignorance but can you write some pseudo code?

  • Sure, in a second step in job 1. Set to t-sql

    if SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) = getdate()

    -- need some formatting conversion here.

    exec sp_startjob jobid=2

  • Im leaning towards this approach. A little more background regarding my requirement. Job 1 step 1 executes every 15 minutes. And step 2 will only need to execute one time per month (on the 1st), but can only execute when step 1 has completed for the last time for a given month.

  • rickyc1 (2/21/2014)


    Im leaning towards this approach. A little more background regarding my requirement. Job 1 step 1 executes every 15 minutes. And step 2 will only need to execute one time per month (on the 1st), but can only execute when step 1 has completed for the last time for a given month.

    you can use what steve said previously as a part of your and then get the information from the link below to check that job 1 finished and poof done...

    http://www.mssqltips.com/sqlservertip/2850/querying-sql-server-agent-job-history-data/

Viewing 6 posts - 1 through 5 (of 5 total)

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