Schedule a DB job based on specific date - database

I have DB job and now I would like to run this job only on specific dates. dates could be in any month like first run on 15 May 2015 and next run woule be 20 July 2015 .. 11 OCT 2015 etc etc.
Through scheduler we dont see such fluxibility. I guess this can be done through some function and call that in scheduler.
Could someone please help me on that.

Your task can be solved without using any additional functions, you can create a schedule with FREQ=YEARLY and with BYDATE clause you can specify an exact dates. For example:
BEGIN
dbms_scheduler.create_schedule('my_sched',
repeat_interval => 'FREQ=YEARLY;BYDATE=0515,0720,1011');
END;
This plsql block will create the schedule named my_sched which contains 15 May, 20 July and 11 OCT of every year. You can use this schedule while creating your jobs.
You can read more about oracle calendaring syntax here: http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sched.htm#BABEJGCH

Related

SQL JOB schedule: how to skip certain month

I need a report that runs once on the following month below:
JAN,FEB,APR,MAY,JUL,AUG,OCT,NOV (essentially skipping MAR, JUN, SEP and DEC)
and this is how I do it (I had to have two schedules to achieve it: See screenshot below). and My question does my two-schedule method will get me what I need? is there a better way?
Will this still work in 2024, 2025 and so on?
thanks
The only difference between the schedule is the start date.
THE FIRST Schedule ( I am hoping this report will run on JAN APR JUL OCT)
The second Schedule: ( And the second schedule, I am hoping it will run on FEB MAY AUG NOV)
Simply have a single job that executes monthly and in the t-sql job step
if month(getdate()) in (1,2,4,5,7,8,10,11)
begin
exec...
end

Cron Script to execute a job every 14 days from a given date in specific time zone

I want to execute a Job in CRON for every 14 days from a specific date and timezone.
As an e.g. from JUNE 24TH every 14 days in CST time zone.
Run job every fortnight
The easy way
The easiest way to do this is simply to create the task to run every 14 days from when you want it to first run like:
CREATE TASK mytask_fortnightly
WAREHOUSE = general
SCHEDULE = '20160 MINUTE'
AS
SELECT 'Hello world'
How it works
As there are 60 minutes in an hour, 24 hours in a day and 14 days in a fortnight, ergo that's 20,160 minutes.
Caveat
The above solution does not run the task every fortnight from a given date/time, but rather every fortnight from when the task is created.
Even though this is the simplest method, it does require you to be nominally present to create the task at the exact desired next scheduled time.
As a workaround however, you can create a one-shot task to do that for you the very first time at the exact correct date/time. This means you don't have to remember to be awake / alert / present to do it manually yourself, and you can clean up the creation task afterwards.
The harder way.
Other solutions will require you to create a task which gets run every Thursday (since 2021-06-24 is/was a Thursday, each subsequent Thursday will either be the off-week, or the fortnight week)
e.g. SCHEDULE = 'USING CRON 0 0 * * THU'
Then you will add specific logic to it to determine which one the correct fortnight is.
Using this method will also incur execution cost for the off-week as well to determine if it's the correct week.
Javascript SP
In javascript you can determine if it's the correct week or not by subtracting the start date from the current date and if it's not a mutiple of 14 days, use this as a conditional to short circuit the SP.
const deltaMs = (new Date) - (new Date('2021-06-24'));
const deltaDays = ~~(deltaMs / 86400000);
const run = deltaDays % 14 === 0;
if (!run) return;
// ... continue to do what you want.
SQL
You can also check if it's a fortnight using the following SQL condition in a WHERE clause, or IFF / CASE functions.
DATEDIFF('day', '2021-06-24', CURRENT_DATE) % 14 = 0

Google cloud cron.yaml schedule formatting for custom repetitive interval

I'm struggling to format a cron schedule for gcp properly and the docs aren't really helping me out.
Cron #1: Run every 50 minutes from 11:00 to 21:00 only on the months from march to october inclusive
schedule: every 50 minutes from 11:00 to 21:00 of mar,apr,may,jun,jul,aug,sep,oct
Cron #2: Run every day at 22:00 only on the months from march to october inclusive
schedule: every day 22:00 of mar,apr,may,jun,jul,aug,sep,oct
Neither of those work, but they were one of my attempts. What am I doing wrong here?
Referring to the Formatting the schedule docs below.
There is no supported syntax for your 1st cron:
specifying minutes in an [INTERVAL_VALUE] is only supported by END-TIME INTERVAL and START-TIME INTERVAL formats, but neither of them allows specifying months in the [INTERVAL_SCOPE].
the only format supporting month specification in [INTERVAL_SCOPE] is CUSTOM INTERVAL, but that only supports day specifications in [INTERVAL_VALUE].
But you can achieve an equivalent functionality by using the finer time specification in cron.yaml and making a check for the remaining conditions inside the cron job itself, doing nothing if the condition is not met. So your 1st cron would be achieved with:
this cron.yaml entry:
schedule: every 50 minutes from 11:00 to 21:00
an additional check for the current month inside the cron job itself, doing nothing (just returning) if the month is Jan, Feb, Nov or Dec.
Your 2nd cron is possible using a CUSTOM INTERVAL, you just need to place the hour at the end of the [INTERVAL_SCOPE]. From the doc:
[INTERVAL_SCOPE]: Specifies a clause that corresponds with the
specified [INTERVAL_VALUE]. Custom intervals can include the of
[MONTH] clause, which specifies a single month in a year, or a
comma-separated list of multiple months. You must also define a
specific time for when you want the job to run, for example: of
[MONTH] [HH:MM].
So your entry would be:
schedule: every day of mar,apr,may,jun,jul,aug,sep,oct 22:00

Executing a sql script every month for the first and last 16 days.

I have a script that I have had to ran manually a few times but now it looks like it will need to be ran twice a month. The problem is the dates are dynamic and the job needs to run on the 1st and 16th of every month but it will need to pull all data from the last 16 days. So for example, if we run it on the first of this month (Jan) the dates would be >= 2016-12,16 and <= 2016-12-31
I have been looking at the date function sql server has but I am not really sure if it will work for what I need.
I would look at DateAdd, and add a negative number of dates to the value to go back 16 days.
DATEADD(DAY, -16, GETDATE()).
I would personally just run a script with cron and set it up to run on the 1st and the 16th of every month.

Update data entry for one month and future months

I think it is a straightforward question that requires some macro modification in my file, I will appreciate your help.
I am using this very useful form for data entry (Data Entry Form (Add/View)): http://www.contextures.com/xlForm02.html
I've adjusted it for my purpose (to track staff movements, changes and new starters), see the file here: http://www.filedropper.com/formsheeteditopttest2-creatingonemastersheetv8forstackoverflow
Every worker has a unique ID and a row per month. In the future the manager of these employees will be able to update the sheet (Input) to reflect any changes that are happening to the person (e.g. promotions, changes of site, change to the role name etc.).
So the two scenarios I am trying to do are for A - update to the current worker, B - adding a new starter.
A - when your UPDATE e.g. job level for one person in e.g. March 2017, this change should be reflected for this person for the rest of the year so for April 2017, May 2017 up to December 2017 etc.
B - When you ADD a new starter (e.g in May, 2017), I would like this starter to be added for each month i.e. May, 2017; June, 2017; July, 2017 up to December 2017 as well.
Any idea what to do to the existing macro code in the file for it to work?
Thanks
Ewa

Resources