Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

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

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 19, 2013 11:58 AM
Points: 24, Visits: 54
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


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 1:35 PM
Points: 3,252, Visits: 7,001
Not exactly a bug, it's just the accuracy for datetime data type.
You can read about it here.
http://technet.microsoft.com/en-us/library/ms187819%28v=sql.105%29.aspx



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

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

Add to briefcase

Permissions Expand / Collapse