Learning and using MS SQL Server cursor

Time:2021-11-26

In fact, the cursor has not been used for such a long time using MS SQL server. Previously, similar functions were implemented by using while loop and temporary table. Just now I wrote it with reference to the online example exercise. Understand the concept and syntax of cursors.

In the following code example,
First, declare that you need to use variables in the cursor, that is, temporarily store the data of the processing field.
2. Declare a cursor and select the dataset to be processed.
3. Open the cursor (#8 line of code).
4. Fetch the fetch next data from the cursor to assign a value to the variable.
5. Cycle @ @ fetch_ Status = 0 condition.
6. In the loop block, the first record logic can be processed. In this example, print.
7. After the logic processing is completed, fetch next data from the cursor again to assign a value to the variable. (same as 4 above).
8. Close the cursor.
9. Delete and release the cursor.

Learning and using MS SQL Server cursor 

Execution results:

Learning and using MS SQL Server cursor

Recommended Today

Vue、Three. JS implementation panorama

1、 First, we need to create a Vue project This paper mainly records the process of building panorama in detail, so building Vue project is not described too much. 2、 Install three js npm install three –save npm install three-trackballcontrols –save npm install three-orbit-controls –save npm i three-obj-mtl-loader –save npm i three-fbx-loader –save npm i […]