NinaWilliam
06-03-2008, 07:58 AM
I am trying to write a for loop cursor, and this is my code
DECLARE
slip_Update CURSOR FOR
SELECT * FROM SlipsTEST, SlipdetailsTEST
WHERE SlipsTEST.SlipIdOld = SlipdetailsTEST.SlipIdOld
FOR UPDATE;
BEGIN
OPEN slip_Update;
FOR slip_Update IN slip_Update
LOOP
UPDATE SlipdetailsTEST
SET SlipdetailsTEST.SNO = SlipsTEST.SNO
WHERE CURRENT OF slip_Update;
END LOOP;
CLOSE slip_Update;
END;
Can any one tell me what is wrong with my cursor? I run it in SQL Query Analyzer and it always shows this message:
Server: Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'FOR'.
Server: Msg 170, Level 15, State 1, Line 14
Line 14: Incorrect syntax near 'LOOP'.
Server: Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'END'.
DECLARE
slip_Update CURSOR FOR
SELECT * FROM SlipsTEST, SlipdetailsTEST
WHERE SlipsTEST.SlipIdOld = SlipdetailsTEST.SlipIdOld
FOR UPDATE;
BEGIN
OPEN slip_Update;
FOR slip_Update IN slip_Update
LOOP
UPDATE SlipdetailsTEST
SET SlipdetailsTEST.SNO = SlipsTEST.SNO
WHERE CURRENT OF slip_Update;
END LOOP;
CLOSE slip_Update;
END;
Can any one tell me what is wrong with my cursor? I run it in SQL Query Analyzer and it always shows this message:
Server: Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'FOR'.
Server: Msg 170, Level 15, State 1, Line 14
Line 14: Incorrect syntax near 'LOOP'.
Server: Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'END'.