游标本次循环,跳过某些语句
DECLARE @Name NVARCHAR(50),@NRIC NVARCHAR(15),@PersonID INT
DECLARE CUR_Test1 CURSOR FOR
SELECT [Name],NRIC,PersonID FROM tblCtcPersonTest1
OPEN CUR_Test1
FETCH NEXT FROM CUR_Test1 INTO @Name,@NRIC,@PersonID;
WHILE @@FETCH_STATUS =0
BEGIN
IF EXISTS(SELECT * FROM tblCtcPersonTest WHERE NRIC=@NRIC )
BEGIN
GOTO UPDATE_IMPORT_RESULT;
END
UPDATE tblCtcPersonTest SET Flag='not Go To' WHERE PersonID=@PersonID
IF CHARINDEX('*',@NRIC)>0
BEGIN
INSERT INTO tblCtcPersonTest([Name],[PersonID],NRIC)VALUES(@Name,@PersonID,@NRIC)
END
ELSE
BEGIN
UPDATE tblCtcPersonTest1 SET Remarks='cant insert' WHERE PersonID=@PersonID
END
UPDATE_IMPORT_RESULT:
UPDATE tblCtcPersonTest SET Remarks='Go To' WHERE PersonID=@PersonID
FORNEXT:
FETCH NEXT FROM CUR_Test1 INTO @Name,@NRIC,@PersonID;
END
CLOSE CUR_Test1;
DEALLOCATE CUR_Test1