January 14, 2015 at 7:44 am
hello guys,
As WAITFOR DELAY '00:00:05' is not allowed inside a function, can you please let me know if there is any other simple way to accomplish the wait. - Thanks
this is the code
BEGIN
DECLARE @tempTable TABLE (spid int, ecid int, cpu int,physical_io int,memusage int)
INSERT INTO @tempTable
select spid, ecid, cpu, physical_io, memusage from master.dbo.sysprocesses
-- WAITFOR DELAY '00:00:03'
INSERT INTO @ReturnTable
select top 40 s.spid,Dcpu=s.cpu - t.cpu,Dio=s.physical_io - t.physical_io,Dmem=s.memusage - t.memusage,
login_time,last_batch,status,hostname,program_name,cmd,nt_domain,nt_username,loginame
from master.dbo.sysprocesses s,@tempTable t where s.spid=t.spid and s.ecid=t.ecid order by Dcpu desc, Dio desc, s.spid
return
END
January 14, 2015 at 7:56 am
Why would you want it in function? Whatever reason, it would be highly unrecommened.
However you can use dummy loop:
declare @dtStart datetime=getutcdate()
while datediff(second,@dtStart,getutcdate()) < 3
begin
set @dtStart = @dtStart
end
January 14, 2015 at 8:01 am
i wanna wait for some time(seconds) to get a delta on resources and i want it as a function to sort based on columns
thanks for the reply.
February 8, 2015 at 8:34 am
wannabe1 (1/14/2015)
i wanna wait for some time(seconds) to get a delta on resources and i want it as a function to sort based on columnsthanks for the reply.
You should do this in a stored procedure rather than a function. Doing a WHILE loop to hum around and do nothing for 3 seconds is pretty expensive CPU wise.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 9, 2015 at 11:41 am
wannabe1 (1/14/2015)
i wanna wait for some time(seconds) to get a delta on resources and i want it as a function to sort based on columnsthanks for the reply.
What does the code being in a function have to do with sorting the output?
Don Simpson
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy