Cursors: is used to loop the table from top to bottom, and to concatenate values into strings.
Example:
The Dbo.titles table for the pubs database.
1. Obtain the total price in the table: select sum from Dbo.titles
2. But I want to get a result: Title, price.
Proficient in asp,39 yuan; learning vc++,28; Java programming, 23 USD
The cursor is used:
To declare a cursor:
DECLARE Titprice CURSOR Fast_forward for
Select title, Price from Dbo.titles where price<15
To open a cursor:
Open Titprice
Recycled Mass Collection
FETCH NEXT from Titprice to @strtitle, @strprice
While @ @fetch_status =0
Begin
If @str = ' '
Set @[email protected]+ ': ' +convert (varchar), @strprice)
Else
Set @[email protected][email protected]+ ': ' +convert (varchar), @strprice)
FETCH NEXT from Titprice to @strtitle, @strprice
End
Close Cursors
Close Titprice
Releasing cursors
Deallocate Titprice
Print @str
Usage of the SQL midstream standard