title: Can I abort a specific sql statement after a given timespan?
body: <p>I would like to be able to abort a specific sql statement if it takes longer than a specified number of seconds. How can I do that? </p>
  
  <p>For example, I would like to do something like:</p>
  
  <pre><code>
  SET NextStatementTimeOutSeconds = 60
  SELECT * FROM MyTable
  IF @@LastStatementTimedOut = 1
      PRINT 'Statement timed out after 60 seconds'
  ELSE
      PRINT 'Statement completed in less than 60 seconds'
  </code></pre>
  
  <p>Please note that I made up <code>NextStatementTimeOutSeconds</code> and <code>@@LastStatementTimedOut</code> in order to illustrate what I would like to do.</p>
  
  <hr>
  
  <p>Thanks for the suggestions. I'm thinking about using such a timeout inside a single sql script/batch like the one above, if possible.</p>
  
  <p>Background: We have several stored procedures that I'd like to be faster than X seconds. So I'd call them one after each other; and if one takes more than X seconds, I'd just abort and print a statement like 'sproc 13 takes too long'. The data varies and I'm trying different index changes, so I'd like to time-test all sprocs after such changes in order to make sure that all of them are below X seconds.</p>