Automate daily SQL queries
To automate your SQL queries daily you would first need to setup the automation with AutoSQL and then schedule it using Windows Task scheduler. Take the following steps as described in 3 step to create a SQL automation task in AutoSQL:
- Create an ODBC connection to your database (MS SQL, MySQL, Oracle, Acces, PostgreSQL, …)
- Select the first task in AutoSQLs
- Use the ODBC connection and specify the SQL query
- Specify the export of the results towards CSV, Excel or HTML. Optionally add your email options and don’t forget to setup an SMTP server
Test your automated SQL query
Test your SQL query, output settings and email by clicking on ‘Run action’. This will run the automated query. In case of any error you can still easily correct it here.
If everything worked as it should, you will get a message that the query was successfully executed and the results have been outputted and emailed.
Schedule your query with Task Scheduler
When your action has been tested, you now want to schedule it using the Windows Task Scheduler. First click ‘Get Background Command’ to get the command on your clipboard to automatically executed your actions.
This will copy the command to your clipboard as the message says:
Now you open the Windows Task Scheduler and right click ‘Task Scheduler Library’ and choose ‘Create basic Task’ like in the picture below:
In the first step give it a name like ‘My daily SQL query’:
Run the query daily
Click ‘Next’ to come the ‘Trigger’ section. This is where you can specific the interval of the query being run. This can be daily, hourly, or any other interval. In this example we will run the query daily at 6 AM in the morning:
When the trigger section is complete, you will go to the ‘Action’. Here you choose to ‘Start a program’:
In the ‘Program/script’ box you paste the command on your clipboard by pressing Ctrl+V or right click in the text box and choose ‘Paste’:
Now you can press ‘Finish’ to finalize the task. It will ask if it is correct that you separate the actual tool started (AutoSQL) and the argument. Choose ‘Yes’ to do this:
Now you are done and the query will be run every day at 6 AM.