views:

112

answers:

2

I have a table, named ReportingPeriods, that I want to be populated entirely automatically. In another table, there are attributes CreationDate and ReportingPeriodLength which together will determine the the results of this row. Upon adding a row for this table, we will add a row in ReportingPeriods with the first StartDate as the creation date and EndDate as ReportingPeriodLength days after startDate.

So far, this is simple. However, I wish to check (daily) whether this period has expired. And if it has, I want to start a new row, beginning the day after the EndDate and extending, once again, for ReportingPeriodLength days.

Is this possible to accomplish without manually checking and adding a new row?

Thanks :)

+2  A: 

call a stored procedure from a database job that is run each day. within this procedure, do your check and insert if necessary.

KM
Indeed, this is the route I was thinking. However, how do you get this to run each day?
Chris
Look at SQl Server Jobs. Under SQL Server Agent. It is basically a scheduling utility.
TGnat
when you set up a job you can set up a schedule, just select daily at a certain time (probably in the early AM)
KM
by letting the DB do the scheduling and running the task, you get job history and error logging, no need to worry about other system outages (web server, network, etc.) If the DB is running your job will run.
KM
A: 

Windows Scheduled Tasks is an appropriate tool for this.

You can write a simple script or a C# console application that calls a stored procedure in your database. Add that executable as the command for a new scheduled task and pick an appropriate time.

Damovisa