1、第一種方法,遊標spa
定義遊標 DECLARE cur_ClubHeadCash CURSOR FAST_FORWARD READ_ONLY FOR,循環每行 FETCH NEXT FROM cur_ClubHeadCash INTO @intUserID, @Clubid, @Amountcode
DECLARE @intUserID INT,@Amount INT, @Clubid INT,@AmountTmp INT DECLARE cur_ClubHeadCash CURSOR FAST_FORWARD READ_ONLY FOR SELECT userid,cid,cash FROM #temp WHERE userid not in(1000882) ORDER BY userid ASC OPEN cur_ClubHeadCash FETCH NEXT FROM cur_ClubHeadCash INTO @intUserID, @Clubid, @Amount WHILE @@FETCH_STATUS = 0 BEGIN PRINT @intUserID PRINT @Clubid PRINT @Amount SET @AmountTmp= @Amount*-1 PRINT @AmountTmp --EXEC dbo.PrPsWeb_UpdateClubCash -- @Clubid, -- 13001, -- @AmountTmp, -- '127.0.0.1', -- '管理員減小房卡', -- NULL, -- 0 --EXEC dbo.PrPsWeb_UpdateUserCash -- @intUserID, -- 13000, -- @Amount, -- '127.0.0.1', -- '管理員增長金幣', -- NULL, -- 0 FETCH NEXT FROM cur_ClubHeadCash INTO @intUserID,@Clubid,@Amount END CLOSE cur_ClubHeadCash DEALLOCATE cur_ClubHeadCash DROP TABLE #temp
2、第二種方法,while循環blog
獲取需處理表的全部行以及行號,取最小行號min和最大行號max,進行循環ci
DECLARE @intMinId INT,@intMaxId INT,@intClubID INT,@lngUpdateAmount BIGINT SELECT RowID=IDENTITY(INT,1,1),A.ClubID,A.NeedAmount INTO #templist FROM Game.UserCreateClubDesk AS A WHERE A.ServerID=@intServerID SELECT @intMinId =MIN(RowID),@intMaxId=MAX(RowID) FROM #templist WHILE @intMinId<=@intMaxId BEGIN SELECT @intClubID=ClubID,@lngUpdateAmount=NeedAmount FROM #templist WHERE RowID=@intMinId EXEC dbo.PrPsWeb_UpdateClubCash @intClubID, @sintSourceType, @lngUpdateAmount, '127.0.0.1', @chvMemo, NULL, 0 SET @intMinId=@intMinId+1 END DROP TABLE #templist