Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

WAITFOR DELAY - Shortest Delay Possible? Expand / Collapse
Posted Thursday, September 19, 2013 8:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, August 12, 2016 9:53 AM
Points: 34, Visits: 95
This is baffling me!

I have a proc that will call another proc to clear a record (if one exists) before adding a new one. Both procs work fine and the table ends up correct. However, I've noticed that the proc that clears the record logs that it executed at exactly the sime timeas the new record. This means that I can't see the correct order in my log table. Obviously, as the clearing proc runs BEFORE the proc that adds the new record, it should write it's log record first. The clearing proc runs at least three statements before the second one.

No problem I thought, I'll just drop a WAITFOR DELAY '00:00:00.001' after the clearing proc so that they are at least a millisecond apart and that will fix it.

Trouble is, it doesn't. The still come in at exactly the same time. If I make the delay a second, it works, but that's crap.

I tried:
select GETDATE()
waitfor delay '00:00:00.001'
select GETDATE()
And I seem to get some spurious results for anything less than 10 miliseconds.

Any ideas? Have I found a bug? Do I win a prize?
Post #1496440
Posted Thursday, September 19, 2013 9:23 AM



Group: General Forum Members
Last Login: Today @ 3:15 PM
Points: 7,994, Visits: 17,274
Not exactly a bug, it's just the accuracy for datetime data type.
You can read about it here.

Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

How to post data/code on a forum to get the best help: Option 1 / Option 2
Post #1496457
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse