I’ve got an SQL 2005 SSIS package that does monthly reporting to a government office that is due on the last Thursday of every month. I set up the SQL Server to run the package on the right day. Scheduling the report isn’t a problem.
Right now the SSIS package creates a month to date report. I used two variables. A BeginDate which uses an expression to determine the first day of the month and converts it to a string like “5/1/2012”. Likewise, there’s and EndDate which spits out todays date like “5/3/2012”.
Is there a way to set the BeginDate variable to the day after the last time the report was run? Is there a better way to find out the date for the last Thursday of the prior month?
There are a variety of ways to settle this in my mind.
Option 1
Since you are using SQL Agent, use SQL Agent. When you create your job, click the box to ensure you are saving history. Assuming your database maintenance policies don’t remove job history of the past month, you should be able to write a query to determine when the job step last successfully completed. Running a query like this in an Execute SQL Step will yield the last time the SSIS step ran successfully. All you’d need to do is assign the value of the third element to your EndDate variable
Option 2
Create a custom table and have your job record the last processing date to that table. The process looks to that table at the onset of processing and uses the last date as the end date.
Option 3
Compute the last Thursday of a month in your favorite language (.NET, TSQL, probably even the SSIS expression language would work but I wouldn’t try)
Option 4
Similar to option 1, but use SSIS logging, log to SQL Server and then look for the last successful execution date and use that as your enddate.