Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I need to schedule some queries to run at the beginning of every month (for monthly reports) and I read that creating a JOB in sql server 2008 was the way to go. Unfortunately, I don't have the rights/privileges to use SQL Server Agent at this time. Is there another way of scheduling a few queries to run the first day of every month?

I am running Sql Server 2008 R2 on Windows Server 2008 R2 Standard operating system.

share|improve this question
    
What do you want to do with the output of the queries? Look at it, send it to a file, or ...? –  automatic Mar 9 '12 at 15:09
3  
If these genuinely are reports, why not write them in reporting services (RS) and set up a monthly subscription for them? That functionality is built into RS. –  Damien_The_Unbeliever Mar 9 '12 at 15:13
    
the output of the queries would ideally be saved as excel files or as .csv files. @Damien_The_Unbeliever I don't know why I didn't think of that. I will give that a try. –  JuanVelez Mar 9 '12 at 15:26
    
If the point of running the query is to make an xl/csv once a month and send it to people, then RS is the way to go. Create a report in reporting services that generates the results you want, and then create a subscription that sends it to the right people on the right days. (once a month is one of the options). –  jerry Mar 9 '12 at 21:18
add comment

migrated from stackoverflow.com Mar 10 '12 at 14:40

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 3 down vote accepted

SQL Jobs is indeed the right way about it.

If you don't have the permissions, talk to your manager/DBA in order to set up the job.

If this is not possible, you can use the task scheduler in conjunction with sqlcmd to execute queries on the SQL Server.

Another alternative is to write a windows service that will execute these queries, but in terms of scheduling I would trust the task scheduler over custom code.

share|improve this answer
    
Thanks for the suggestions. I'll try talking first to the DBA (but hes new on the job so he's a little paranoid and thinks that any little thing will cause the serve to explode! lol) if i still cant get the permissions then i'll try one of the other methods you have listed. –  JuanVelez Mar 9 '12 at 15:32
add comment

If you absolutely cannot use SQL jobs to do it, you could use C# to write a program which connects to the database and runs the queries. Then, compile this program into an executable and write a batch job which runs the executable from Windows Task Scheduler.

share|improve this answer
add comment

Sql Server Agent really is the best way to do it so try and get access if you need it.

If you have to, you could create a 'hack' - one possible way is to find a stored proc that you know gets called at least daily and add a final step in there to check if DATEPART('dd', getdate()) = 1. If so, call your other proc that you'd like to be 'scheduled'.

Ugly, but would work if needed!

share|improve this answer
    
hehehe cool, I'll keep that in mind in case all else fails. –  JuanVelez Mar 9 '12 at 15:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.