Reoccurring SQL job to run on the 2nd and 4th Thursday of every month - sql

I need a job to run on the 2nd and 4th Thursday of every month. I know I can set up a job to run every two weeks but that logic doesn't work when a month eventually hits a five week span. Is it possible to set this up using the SQL Server Agent Schedule? If not, does anyone recommend another method?

Create two schedules on the job, one that runs on the second Thursday, and one that runs on the fourth.
Under the Frequency heading on the Scheduler, change the Occurs drop down to Monthly to get to the options you need.

Related

Why query takes indefinite amount of time to execute in certain date range?

I have a query that I'm trying to execute and when I take certain range, for example, 7th week of 2022, it never executes, but when I'm running query for the same week in previous year it executes well. What could be the reason of such behaviour?
It seems that it goes like that in all date ranges of February 2022.
May be previous year has less data so the related partition returned the result quickly.
check on the segment host, is the segment process busy, maybe try pstack the query process and see what its doing

How to schedule biweekly SSRS subscription on 2017 report server

I would like my report to be sent biweekly on a Monday. Right now, I created two different subscriptions that sends the report on every 2nd and 4th week. I am not sure it would be accurate considering, I would like the send the report Monday after Pay period ends. What's a best way to approach to this?
A subscription can be created by Week and scheduled to repeat after 2 weeks. Monday can be selected as the day.
The schedule will show Every Monday of every two weeks.

Running APScheduler job the day before the 1st and 3rd Monday each month

I have an APScheduler job that creates a report our client has requested for the first and third Mondays of the month.
To deliver that in time, I want to run the job the day before the first and third Monday, which can't be specified directly in APScheduler.
I noticed another user had this question as well, describing the request as impossible, in the comments of Running APScheduler Job Every nth Day of Month
Here's how I solved it:
scheduler.add_job(func, 'cron', 'day_of_week'='sun', 'day'='last,1-6,14-20')
By specifying the day of the week, and then specifying the days in the month that could apply, it will fire the day before the first and third Mondays. It only fires when all the conditions are met, so the other dates (which won't be Sunday) don't fire.

T-SQL Task generator script

I need to create a T-SQL (I`m using SQL Server 2008 Express) script (procedure/function) that takes entries from a "Tasks" table and generates only the tasks planned to occur in the next 5 hours.
In the "Tasks" table I should have tasks with job like properties :
Occurrence : One time or Recursive
Frequency : every x Days, Weeks, Months
Depending on the Frequency :
For Daily : every x hours,minutes
For Weekly -Days of the week when the task should occur
For Monthly - The first,second,last -day,week day,weekend -
day of week OR The 1st, 2nd, 3rd..31st of the month.
When I run the script I should get only the tasks that will occur in the next 5 hours or less in the case if task occurs every x minutes.
So what this script should actually do is use all the options from a SQL Server Job for a task.
Example1: I create a task "Check email" that occurs every day, between 14:00 and 15:00 . When i run the script at 09:00 I would get Task:"Check email" Time:5 hours left until task, because it occurs every day, i should be able to get this result every day when I roll the script ,only if that 5 hours or less range .
Example2: A task "Send hours report" that occurs Monthly, on the 1st week day (not weekend), at 01:00 PM . Running the script on the first week day of the month at 08:00 AM I should get Task:"Send hours report" Time:5 hours until task
I know it's a quite big request but hopefully someone will find it easy what for me seems pretty hard.
You should also store somewhere the date/time of the last execution of each job (at least for jobs that are configured for every x hours/minutes). The idea is to calculate the next execution date/time for each job, and return it if it's less than 5 hours away. If the job is configured for every x hours/minutes, use DATEADD and check if the result is within the configured timeframe. If the job is configured for daily (at a specified time), just check if the specified time is less than 5 hours away (but still in the future). I have done a similar feature and it's not an easy thing to check for all cases (it took me a few days of coding).

Scheduling job in sql server mgmt studio to run for 'x' days in a month

How do I run a job in Sql Server Agent in (SQL Server Management Studio) for 'x' number of days in a month?
eg: Every 1st.2nd and 3rd of every month
The problem is I am not sure of these days! The user will specify the 'x' number of days!
For instance, the user feels for the month of April he wants the job to be scheduled on 'x' days. Here x= 1st,2nd and 4th of April.
And for the month May he feels to schedule on 'x' days. Here x= 7th,8th and 10th!
Is it possible to schedule in such a way?
Is there any script to schedule this???
Make a schedule that's run on those three days. Assign this job to that schedule.
(To elaborate and make it perfectly clear).
Make three schedules (Rightclick Jobs, Manage Schedules).In new schedules choose - Recurring on monthly. One starts the 1st, one starts the 2nd, one starts the 3rd of every month (for example, or x times for whatever day of month you wish).
Name these schedules something that's easy for you to spot in a list.
On the job you wish to run on these days, properties on it, schedule, then pick the schedule(s) you want to assign to the given job.
That should be all.
If the schedule is user defined then I'd probably just schedule the job to run every day and have the first step be to check whether it should be running today and if not exit.
Check Howto Schedule a Job and follow the Instructions of cairnz.