保存时创建计划事件引发错误

时间:2019-02-28 06:48:19

标签: sql-server sql-server-2012 heidisql

我将创建一个计划事件,该事件将归档“在线”为“ Y”的所有记录循环,并将其设置为“ N”。

为此,我创建了该事件,但是当我保存该事件时,出现了错误

  

SQL 102:不正确的语法新版本'LOGOUT',附近的不正确语法   'CURSOR'

我使用HeidiSQL和MS SQL Server 2012

    CREATE EVENT "LOGOUT"
    ON SCHEDULE
        EVERY 1 DAY STARTS '2019-02-28 00:00:00'
    ON COMPLETION NOT PRESERVE
    ENABLE
    COMMENT ''
    DO BEGIN
    DECLARE @MyCursor CURSOR;
    DECLARE @MyField VARCHAR;
    BEGIN
        SET @MyCursor = CURSOR FOR
        select Online from dbo.ActiveUser
            where Online = 'Y'      

        OPEN @MyCursor 
        FETCH NEXT FROM @MyCursor 
        INTO @MyField

        WHILE @@FETCH_STATUS = 0
        BEGIN
          Update dbo.ActiveUser Set Online = 'N'
          FETCH NEXT FROM @MyCursor 
          INTO @MyField 
        END; 

        CLOSE @MyCursor ;
        DEALLOCATE @MyCursor;
    END
END

0 个答案:

没有答案