SQL游标 循环处理插入、修改语句

DECLARE @Action nvarchar(50)
DECLARE @Remark nvarchar(100)
DECLARE myCusor CURSOR FOR
SELECT [Action],Remark FROM UserVisit WHERE 
[Action] LIKE '获取验证码%'
AND UserName='' AND Remark<>''
OPEN myCusor
FETCH NEXT FROM myCusor INTO @Action,@Remark
    WHILE @@FETCH_STATUS = 0
    BEGIN
    	IF (SELECT COUNT(1) FROM CaiCaiUserImport WHERE EncryptedMobile=@Remark) <>''
    	BEGIN
    		DELETE CaiCaiUserImport WHERE EncryptedMobile=@Remark
    	END
    	INSERT INTO CaiCaiUserImport
		(
			Notes,
			EncryptedMobile
		)
		VALUES
		(
			@Action,
			@Remark
		)
        print (@Action+ '  '  +@Remark)
        FETCH NEXT FROM myCusor INTO @Action,@Remark
    END
    CLOSE myCusor
    DEALLOCATE myCusor


阅读更多
换一批

没有更多推荐了,返回首页