游标循环时跳转

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

上一篇:游标循环跳过本次循环,循环下一行


下一篇:详解 java CompletableFuture