Usage of the SQL midstream standard

Source: Internet
Author: User

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

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.