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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| 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 |