AUTOMATE DAILY SQL QUERIES
Make Life Easier
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 steps to create a SQL automation task in AutoSQL:
- Setup a connection to your database (MS SQL, MySQL, Oracle, Acces, PostgreSQL, …)
- Specify a query and test it to see if you get the expected result
- Define the output where you can write to Excel, CSV, HTML or the email itself
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 you have multiple actions, you can also choose ‘Run all’.
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 to run daily. This can be done by clicking the ‘Schedule’ button. It wil help you to create scheduled tasks in Windows Task Scheduler.
In the pop up window click on ‘Add new’ to create a new task in Windows Task Scheduler.
Choose the time you want to run it daily in the ‘New trigger’ dialog:
After defining the schedule, you will get a final screen for specifying the details of the scheduled job. By default it will get the same name as the AutoSQL job file appending with the current time. In this screen you can also change the security settings. This is important as it determines if the job can be ran on the background and which credentials are used.
If you choose the job to ‘Run wether user is logged on or not’ it will finaly prompt you for the password. This is standard for Windows Task Scheduler.
That’s it! Now your SQL query will run daily at the time specified and it will run the query, write the output to the Excel file and send it by mail.