Does SQL Query return a value if it takes more than x seconds?

Is it possible to complete an executable query and return a certain value (for example, return value = 1) if the SQL query takes longer than X seconds?

Could you give a specific example of a basic query. For example, in SQL:

select * from test

If this query takes more than 10 seconds to complete, it should return: 1 as the result.

I am using SQL management studio.

+4
source share
3 answers

Yes it is possible. You can use threading

Check here for a few examples.

Can we use threads in PL / SQL?

0
source

DBPROP COMMANDTIMEOUT, - TRY CATH , SQL .

0

I hope this works for you .. I set the usual logic for this.

declare @Starttime datetime=getdate()


select * into #tmp from test


if DATEDIFF(SECOND,@Starttime,getdate()) >10
begin
   select 1
end
0
source

Source: https://habr.com/ru/post/1668500/


All Articles