title: How to automatically trigger a query at specific time in SQL Server
body: <p>How can I run this query using auto trigger 5 minutes before the time of next prayer?</p>
  
  <pre><code>SELECT 
      DATEADD(minute, -5, (SELECT TOP 1 TIME 
                           FROM prayertimes 
                           WHERE Time &gt; sysdatetime())) AS TIME
  </code></pre>
  
  <p>Here are details of the <code>prayertimes</code> table:</p>
  
  <pre><code>Id  P_id  TIME
  ---------------------------------
  698  3    2016-10-08 15:31:00.000
  699  4    2016-10-08 18:02:00.000
  700  5    2016-10-08 19:32:00.000
  701  1    2016-10-09 04:59:00.000
  702  2    2016-10-09 12:08:00.000
  703  3    2016-10-09 15:30:00.000
  704  4    2016-10-09 18:02:00.000
  705  5    2016-10-09 19:32:00.000
  </code></pre>
  
  <p>Let us say that next datetime is <code>2016-10-08 15:31:00.000</code>. </p>
  
  <p>Then I want to trigger the query automatically at <code>2016-10-08 15:26:00.000</code>.</p>
  
  <p>Any stored procedure?</p>
  
  <p>Thanks</p>