4

Is it possible to terminate an executing query and return a specific value (e.g return value = 1 ) if a SQL query runs for longer than X seconds?

Could you please give a concrete example with a basic query. For example in SQL:

select * from test

If this query is taking more than 10 seconds to execute, it should return: 1 as the result.

I am using SQL management studio.

3 Answers3

0

Yes it,s possible. You can use Threading

Look here some examples

Can We use threading in PL/SQL?

Community
  • 1
  • 1
Kamil Ibadov
  • 1,436
  • 2
  • 20
  • 44
0

You can use DBPROP COMMANDTIMEOUT to specify the timeout and use a TRY CATH on your client because, in SQL, the connection timeout can not be recovered.

0

I hope this will work for you.. i have put custom logic for that..

declare @Starttime datetime=getdate()


select * into #tmp from test


if DATEDIFF(SECOND,@Starttime,getdate()) >10
begin
   select 1
end
Darshak
  • 859
  • 7
  • 18