I am trying to tune a query and would like to test a few pieces during after hours, when there isn't a lot of traffic on the server. I am going to benchmark the individual queries and write the results to a table to check in the morning, i.e.
waitfor time '22:00';
declare @timer datetime
declare @time float
declare @query nvarchar(max)
set @query = N'select ...'
set @timer = getdate()
exec sp_executesql @query
set @time = datediff(ss,@timer,getdate())
The problem is, I won't be able to manually monitor the queries, and I don't want to risk having something run for hours. Is there any way, using T-SQL to set a timeout so that this query cancels after, say 10 minutes?
Other questions on SE suggest that there is now way to do this, or that it can be done for a scheduled job, which I do not have access to create, but I am searching for any alternative or creative solutions.