Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 UPDATE with GETDATE() values always different

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2011-12-19 : 10:01:13
Hi all,
having a simple UPDATE, like this:

UPDATE dbo.Table1
SET UpdateDate = GETDATE
WHERE ID BETWEEN 1 AND 10

is it possible to have the UpdateDate fild with datetime values always different (a millisecond it's enough).


Thank you.

Luigi

Ifor
Aged Yak Warrior

700 Posts

Posted - 2011-12-19 : 10:23:39
An odd requirement.
As datetime is only accurate to 3.333... ms, something like the following should work:

UPDATE dbo.Table1
SET UpdateDate = DATEADD(ms, ID * 4, CURRENT_TIMESTAMP)
WHERE ID BETWEEN 1 AND 10
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-19 : 11:03:27
if you want more accuracy use datetime2

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2011-12-19 : 14:00:35
Thanks a lot, in this way is perfect.
Luigi
Go to Top of Page
   

- Advertisement -