Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Custom SQL Agent job schedule to run on the 5th working day of each month Expand / Collapse
Author
Message
Posted Tuesday, August 2, 2011 2:37 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, October 23, 2014 7:06 AM
Points: 247, Visits: 703
I have the need to send a suite of SSRS reports to a client on the 5th working day of the month. Is there a way of either:

1) setting a subscription to run on this day for the reports
2) set a sql agent job to run on this day

I would ideally like to know both if possible. Is it possible to build custom schedules in sql agent? I have a table of dates and another of holiday dates which can be used to find the 5th working day of the month but I don't know how to apply it to a schedule.
Post #1152336
Posted Tuesday, August 2, 2011 7:55 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, December 18, 2014 9:54 PM
Points: 727, Visits: 1,436
You could do it with a SQL Agent Job pretty easly. Just setup a pre-populated list of the 5th business day each month. The run an IF statement like below.

IF (select * from 5thdayofmonth) = getdate()
BEGIN


-- Run report logic here.

END

Don't know of a way to do this in SSRS Scheduling Manager.

Fraggle
Post #1152532
Posted Tuesday, August 2, 2011 8:07 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, December 11, 2014 6:43 PM
Points: 2,838, Visits: 8,570
I have a need to pre-populate a list of the 5th business day each month. Any idea how to do that ?


Post #1152554
Posted Tuesday, August 2, 2011 8:10 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:06 AM
Points: 20,585, Visits: 9,625
Agreed, you'll have to use a calendar table and a simple if statement to block / let the subscription run.


Keep in mind that those jobs are rebuilt every time the subscription changes (this includes password update).

So that solution can get annoying really fast if it's not properly scripted.
Post #1152557
Posted Tuesday, August 2, 2011 8:14 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:06 AM
Points: 20,585, Visits: 9,625
homebrew01 (8/2/2011)
I have a need to pre-populate a list of the 5th business day each month. Any idea how to do that ?



WITH    CTE ( dt, rn )
As (
SELECT
dt
, ROW_NUMBER() OVER ( ORDER BY dt ) AS rn
FROM
dbo.Calendar
WHERE
Y = YEAR(GETDATE())
AND M = MONTH(GETDATE())
AND IsBusDay = 1
)
SELECT
'RUN SUBSCRIPTIONS'
FROM
CTE
WHERE
rn = 5
AND dt = DATEADD(D , 0 , DATEDIFF(D , 0 , GETDATE()))

IF @@ROWCOUNT = 1
SELECT 'sp_startjob'
ELSE
SELECT 'NOTHING TO DO'


Script to load my Calendar table.

http://www.sqlservercentral.com/Forums/Attachment8839.aspx
Post #1152560
Posted Thursday, October 31, 2013 12:49 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, December 22, 2014 8:35 PM
Points: 39, Visits: 151
Thank you for this script, it was one of the final pieces to my having to run a sub on the 3rd business day of every month.

For anyone who is interested:
Paul Turley has a blog that lists how to get the GUID associated with a individual sub in the SSRS Report Manager.

https://sqlserverbiblog.wordpress.com/2010/03/11/manually-starting-a-report-subscription/#comment-1781

Then you use the command:

use msdb

EXEC sp_start_job @job_name = 'XXXXXXX-8FA9-4DFD-8677-34D451A75C74'

and the subscription fires at the time the script is completed, so it doesn't matter what the days that are in the sub are set for.

Also, I used a Aux_Calendar table from:

http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html

(no author listed, but he is one smart cookie)

Basically with his number table and calendar with this CTE script and the GUID I can now send any report on any set of days that a manager can dream up.
Post #1510387
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse