How to setup SQL Server Agent job script automation in SQL Server.

We will use script to check Queue stats over a period of time, which will help with troubleshooting.


  1. Firstly, check that SQL server Agent service is running. Open SQL Server Configuration Manager.
    Under the SQL Server Services >> SQL Server Agent state should be running, if is not right click and Start
  2. In SQL Management Studio click on the SQL Server Agent to collapse all options.
  3. Right click on Jobs and select New Job, new window will pop up. There are few fields to fill out in the General section as. Name, Owner - This needs to be iQSonar username used for installation. Category can be left default, Description .. Make sure that Enabled at the bottom is ticked as well.
  4. Navigate to Steps tab and at the bottom click on New. New pop up window will open.

    Fill out the Name Type leave as default, Runas: iQSonar user setup in SQL server, or can be left blank.  
    Database: This needs to be iQSonar Db selected.
    In the box where is yellow + char paste the script and press Parse, so SQL will check for any mistakes etc.
    Once all is done click Ok.
  5. Back in Job Properties window navigate to Schedules.

    New window will pop up.

    Once again fill out the name etc.
    This part can be setup in many ways all depends for how log one want to run the script and how often it should be executed.
    We will use the setup in the screenshot.
    IMPORTANT NOTE: Under the Daily frequency field Starting at: HAS TO BE SET AHEAD THAN CURRENT TIME! otherwise Job will not be executed.
  6. If satisfied with the Schedulers setup, click Ok.
  7. Close the Job Properties, Job is now setup.
  8. Is it your JOB running? If one setup to start running the scheduler at 02:00 PM give it 5 min and Open a new Query window and check the newly created table " model.t_Results" if it's populated with results by executing this SQL query
    SELECT * FROM model.t_Results
    We should see every 5 min one row to be added to the table.