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 2005 Forums
 Transact-SQL (2005)
 Something similar to event in mysql for MS SQL

Author  Topic 

headbuzz
Starting Member

11 Posts

Posted - 2010-02-22 : 15:11:34
Hi, Can someone help me out in figuring out the MS SQL equivalent of the following for mysql:

CREATE EVENT
e
ON SCHEDULE
EVERY 5 SECOND
STARTS CURRENT_TIMESTAMP + INTERVAL 5 SECOND
DO
UPDATE names SET names.count=names.count+1;


I'm basically trying to increment the values of all the rows under a particular column every 5 seconds. I could do it easily in mysql but when I'm trying to do it for SQL, I don't know what to do.

I came up with an incomplete function that I'd maybe use, but I do not know how to trigger it every 5 seconds(the names of the variables do change). I wasted more than 3 days on this. I need some help desperately!!!

CREATE FUNCTION lastday ( @joindate DATETIME)
RETURNS INT
BEGIN
DECLARE @referdate DATETIME
DECLARE @count INT
DECLARE @i DATETIME

SET @referdate = CAST(YEAR(@joindate) AS VARCHAR(4)) + '/' +
CAST(MONTH(@joindate) AS VARCHAR(2)) + '/01'
SET @referdate=DATEADD(DD,-1,DATEADD(M, 1, @referdate))
IF(day(@referdate)-day(@joindate)>=15)
SET @count = 1
ELSE
SET @count = 0

WHILE (@i!=0)
BEGIN
SET @referdate=DATEADD(SECOND,5,@referdate)
SET @count=@count +1


RETURN @count

END

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-02-22 : 16:34:12
http://msdn.microsoft.com/en-us/library/ms186273(SQL.90).aspx
Go to Top of Page
   

- Advertisement -