Unix Technical Forum

sleep for n seconds

This is a discussion on sleep for n seconds within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi I am trying to use the WAITFOR function to make each loop in a cursor occur every 4 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:50 PM
Matt
 
Posts: n/a
Default sleep for n seconds

Hi

I am trying to use the WAITFOR function to make each loop in a cursor
occur every 4 seconds until the curdb is empty

the prtocedure is as follows

---------------- start
create procedure q_additionalrabatt
@additionalrabatt float,
@ordernr int

AS

declare @ordradnr int

declare curdb cursor for select ordernr, ordradnr from orp where
ordernr = @ordernr
for read only

open curdb

fetch curdb into @ordernr, @ordradnr

while @@fetch_status = 0
begin

update orp
set orp.rabatt1 = (orp.rabatt1 + @additionalrabatt)
where orp.ordernr = @ordernr and
orp.ordradnr = @ordradnr

fetch curdb into @ordernr, @ordradnr

end

close curdb
deallocate curdb

------------------- end

I need to make sure, that before it fetches the next row it waits 4
seconds before executing the next loop.

Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:50 PM
Dan Guzman
 
Posts: n/a
Default Re: sleep for n seconds

You can use WAITFOR DELAY like the example below. See the Books Online
for details.

CREATE PROCEDURE q_additionalrabatt
@additionalrabatt float,
@ordernr int
AS

SET NOCOUNT ON

DECLARE @ordradnr int

DECLARE curdb CURSOR LOCAL FOR
SELECT
ordernr, ordradnr
FROM orp
WHERE
ordernr = @ordernr

OPEN curdb

WHILE 1 = 1
BEGIN

FETCH curdb
INTO @ordernr, @ordradnr

IF @@FETCH_STATUS = -1 BREAK

IF @@FETCH_STATUS = 0
BEGIN

UPDATE orp
SET orp.rabatt1 =
(orp.rabatt1 + @additionalrabatt)
WHERE orp.ordernr = @ordernr AND
orp.ordradnr = @ordradnr

WAITFOR DELAY '00:00:04'

END

END

CLOSE curdb
DEALLOCATE curdb
GO



--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Matt" <matt@fruitsalad.org> wrote in message
news:b609190f.0309100058.593a5318@posting.google.c om...
> Hi
>
> I am trying to use the WAITFOR function to make each loop in a cursor
> occur every 4 seconds until the curdb is empty
>
> the prtocedure is as follows
>
> ---------------- start
> create procedure q_additionalrabatt
> @additionalrabatt float,
> @ordernr int
>
> AS
>
> declare @ordradnr int
>
> declare curdb cursor for select ordernr, ordradnr from orp where
> ordernr = @ordernr
> for read only
>
> open curdb
>
> fetch curdb into @ordernr, @ordradnr
>
> while @@fetch_status = 0
> begin
>
> update orp
> set orp.rabatt1 = (orp.rabatt1 + @additionalrabatt)
> where orp.ordernr = @ordernr and
> orp.ordradnr = @ordradnr
>
> fetch curdb into @ordernr, @ordradnr
>
> end
>
> close curdb
> deallocate curdb
>
> ------------------- end
>
> I need to make sure, that before it fetches the next row it waits 4
> seconds before executing the next loop.
>
> Matt



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com