cancel
Showing results for 
Search instead for 
Did you mean: 

Is WAITFOR TIME dangerous?

Breck_Carter
Participant
1,638

I must confess, I have often wanted to use WAITFOR TIME because that's what I have: a desired point in time that I want the code to wait for.

However, I have always ended up using WAITFOR DELAY even if it means doing extra work; e.g., a DATEDIFF calculation.

My concern is this line from the Help: If the current server time is greater than the time specified, processing is suspended until that time on the following day.

Consider the following pseudo-code:

SET @t = obtain or calculate a desired "wait for" time 
   that is 0.01 seconds in the future;
Perform some operation that might take more than 0.01 seconds to perform;
WAITFOR TIME @t;

Most of the time, WAITFOR will wait for less than 1/10th of a second. Sometimes, however, CURRENT TIME may be > @t, which means the WAITFOR waits for about 24 hours.

Egad! Zounds! That's not what I want!

What I think I want is WAITFOR TIMESTAMP. Until then, I'll stick to WAITFOR DELAY.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_duemesnil
Participant

I would vote also for an enhanced behaviour. WAITFOR TIME is only usefull if you build something like a scheduler.

VolkerBarth
Contributor

Kind of funny, Breck's question has WAITed FOR a long TIME to get an answer:)

thomas_duemesnil
Participant

I used the Command the first time and the documentation is really strange. Wine also gets better when you let it breath.

Answers (0)