記錄下今天用到的遊標:post
DECLARE @TempID INT
DECLARE @Number INT
SET @Number=1
DECLARE myCursor CURSOR FOR
SELECT MemberID FROM dbo.Member
OPEN myCursor
FETCH NEXT FROM myCursor INTO @TempID
WHILE(@@fetch_status=0)
BEGIN
UPDATE dbo.Member
SET MemberName='測試會員'+ CONVERT(VARCHAR,@Number,50)
WHERE MemberID=@TempID
SET @Number=@Number+1
FETCH NEXT FROM myCursor INTO @TempID
END
CLOSE myCursor
DEALLOCATE myCursor測試
待續.....fetch
DECLARE @id INT
DECLARE @money INT
DECLARE cursor1 CURSOR FOR
SELECT IntegrateCardID,RemainSum FROM dbo.IntegrateCard
OPEN cursor1
FETCH NEXT FROM cursor1 INTO @temp,@money
WHILE ( @@fetch_status = 0 )
BEGIN
UPDATE dbo.IntegrateCard
SET PreRecharge = @money
WHERE IntegrateCardID = @id
FETCH NEXT FROM cursor1 INTO @TempMemeberID
END
CLOSE cursor1
DEALLOCATE cursor1blog