SqlServer basics: cursor

Source: Internet
Author: User
Record the cursor used today: DECLARE @ TempIDINTDECLARE @ NumberINTSET@Number1DECLAREmyCursorCURSORFORSELECTMemberIDFROMdbo.MemberOPENmyCursorFETCHNEXTFROMmyCursorINTO @ TempIDWHILE (@ fetch_status0) BEGINUPDATEdbo. Member

Record the CURSOR used today: 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

Record what is used todayCursor:

DECLARE @ TempID INT
DECLARE @ Number INT
SET @ Number = 1
DECLARE myCursor CURSOR
SELECT MemberID FROM dbo. Member
OPEN myCursor
Fetch next from myCursor INTO @ TempID

WHILE (@ fetch_status = 0)
BEGIN
UPDATE dbo. Member
SET MemberName = 'test member '+ CONVERT (VARCHAR, @ Number, 50)
WHERE MemberID = @ TempID
SET @ Number = @ Number + 1
Fetch next from myCursor INTO @ TempID
END
CLOSE myCursor
DEALLOCATE myCursor

To be continued .....



DECLARE @ id INT
DECLARE @ money INT
DECLARE cursor1 CURSOR
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.