Home > database >  The cursor problem
The cursor problem

Time:09-16

Big help of database, Tony going to cry (> <)

CodePudding user response:

Come to a big help me

CodePudding user response:

Come and save me a heavyweight

CodePudding user response:

There is not even a table structure, what is the primary key table?
Assuming that the primary key is ID, example
 
DECLARE _cursor CURSOR SCROLL FOR
SELECT id, grade FROM sc WHERE grade & lt; 100 the AND grade & gt; ASC=60 ORDER BY id;

The OPEN _cursor; - open the cursor

DECLARE @ id VARCHAR (40);
DECLARE @ grade INT.

The fetch first clause _cursor INTO @ id, @ grade
WHILE (@ @ FETCH_STATUS=0)
The BEGIN
The UPDATE sc
The SET of grade=CASE WHEN @ grade & lt; THEN @ 70 grade + 3
The WHEN @ grade & lt; THEN @ 80 grade a + 2
The WHEN @ grade & lt; THEN @ 99 grade + 1
The ELSE @ grade - 99 remains the same?
END
WHERE id=@ id

The FETCH NEXT FROM _cursor INTO @ id, @ grade;
END;
The close _cursor;
Deallocate _cursor
  • Related