SQL Jobs

  • Hi,

    I have a job having two steps. I want run step1 every 30mins.Second step need to be run once in a day. Is it Possible?

  • make step 2 test for a specific time window as part of it's process.

    i start a trace @7am if it's not running, and turn it off at 5pm for example:

    --###############################################################################################

    --startup logic if required.

    --###############################################################################################

    IF EXISTS (SELECT * FROM master.sys.traces WHERE PATH LIKE '%MyDMLTrace%' AND STATUS = 0)

    AND (DATEDIFF(hh,DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0),GETDATE()) = 7) --7am, not started?

    BEGIN

    EXEC sp_trace_setstatus @TRACEID, 1 ---start trace

    END

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • EDIT: As the OP didn't mention any dependency, I agree with the other posters - create two jobs if the steps are independent of each other.

    One option (if and only if step 2 is dependent on step 1):

    Step 2's process should log when it was last run/every time it runs.

    Step 2 then first checks to see if it's run this day/within the last 24 hours, and if not, it runs. This will cover you in case the job's doesn't run every 30 minutes for awhile (SQL Server patch + reboot meant services were down during one or more scheduled interval, for example).

  • Why don't you just create two jobs?

  • I'm just throwing this to table so I could be completely wrong here ...experts would be able to put insight ...I think it be done using a batch file .. a batch file will have a code which will call the first step from the job every half an hour and the query to call second step will be executed only once at specific time of server.

    Job setting could be set as follows

    Job step 1 : On success ..quit job with success

    On failure --- Quit job reporting failure

    Job step 2 : On success ..quit job with success

    On failure --- Quit job reporting failure

  • crmitchell (2/11/2014)


    Why don't you just create two jobs?

    +1, keep it simple.

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

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