SqlServer基础:游标

WBOY
發布: 2016-06-07 15:24:54
原創
950 人瀏覽過

记录下今天用到的 游标 : 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

记录下今天用到的游标

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

待续.....



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 cursor1

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板