Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

utcgetdate - stop a query after x time

Hi

Im looking for a way to stop a query after a given period of time or a specific timestamp, like

select * from bigtable where getutcdate() < "2015-06-19 15:00:00"

In Sybooks, the utcgetdate function mentions that :

Returns a date and time where the value is in Universal Coordinated Time (UTC). getutcdate is calculated each time a row is inserted or selected.

But, when running the following command, even for a long time, the timestamp value doesn't change at all...  not even microseconds. Looks like it get cached 

select top 50000 convert(char(26),getutcdate(),109),* from bigtable

I can guess that this may incur a reasonable overhead since time function may requet a spinlock to get the clock value, so , i was planning to wrap up this time check in a function and pass a number (probably the sequential numeric key at hand)  and get the modulus of this number by 1000

The idea is also only use this construction on very specific queries which may be triggered by the end of the day and the results expected on the next day, but they should not get into business hours....

Someone have some ideas to share?

Thanks!

Former Member
replied

Here's the full code and example output:

create procedure xp_f_getdate (@d datetime output)
as
  set @d = getdate()
go

create  function f_getdate (@i int)
returns datetime
as
   declare @v datetime
   exec xp_f_getdate @v output
   return @v
go

1> select convert(varchar,dbo.f_getdate(so.id),109)
2> from  sysobjects so, syscolumns, sysindexes
3> go
[...]
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:520AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:523AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:526AM
Jun 20 2015  1:35:27:530AM
Jun 20 2015  1:35:27:530AM
Jun 20 2015  1:35:27:530AM
Jun 20 2015  1:35:27:530AM
Jun 20 2015  1:35:27:530AM
[...]

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question