使用游标
DECLARE MY_CURSOR CURSOR --SCROLL DYNAMIC /*SCROLL表示可随意移动游标指针(否则只能向前),DYNAMIC表示可以读写游标(否则游标只读)*/
FOR
SELECT M_ID,M_USERNAME,M_AGE FROM TMEMBER
OPEN MY_CURSOR
DECLARE @M_ID SYSNAME
DECLARE @M_USERNAME SYSNAME
DECLARE @M_AGE AS SYSNAME
FETCH NEXT FROM MY_CURSOR INTO @M_ID,@M_USERNAME,@M_AGE
WHILE(@@FETCH_STATUS=0)
BEGIN
IF(@M_AGE = 1)
BEGIN
UPDATE TMEMBER SET M_AGE = '0' WHERE CURRENT OF MY_CURSOR
END
FETCH NEXT FROM MY_CURSOR INTO @M_ID,@M_USERNAME,@M_AGE
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
FOR
SELECT M_ID,M_USERNAME,M_AGE FROM TMEMBER
OPEN MY_CURSOR
DECLARE @M_ID SYSNAME
DECLARE @M_USERNAME SYSNAME
DECLARE @M_AGE AS SYSNAME
FETCH NEXT FROM MY_CURSOR INTO @M_ID,@M_USERNAME,@M_AGE
WHILE(@@FETCH_STATUS=0)
BEGIN
IF(@M_AGE = 1)
BEGIN
UPDATE TMEMBER SET M_AGE = '0' WHERE CURRENT OF MY_CURSOR
END
FETCH NEXT FROM MY_CURSOR INTO @M_ID,@M_USERNAME,@M_AGE
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR