Method 2 of SQL query and data traversal [cursor + WHILE LOOP]

Source: Internet
Author: User

The following uses the MERs table in the northwind database in SQL Server 2000 as an example,

UseCursor + WHILE LOOPTo traverse the companyName column in the MERs table.

Declare @ customer nvarchar (50)

Declare pcurr cursor
Select distinct companyName from MERs

Open pcurr
Fetch next from pcurr into @ customer

While (@ fetch_status = 0)
Begin


Print (@ customer)
Fetch next from pcurr into @ customer

End

Close pcurr
Deallocate pcurr

 

After running, the output result is as follows:

(The number of affected rows is 91)

Alfreds futterkiste
Ana Trujillo emparedados y helados
Antonio Moreno taquer ía
Around the horn
Berglunds snabbk öp
Blauer see delikatessen
Blondesddsl p è re et fils
Bó Lido comidas preparadas
Bon app'
Bottom-dollar markets
B's beverages
Cactus comidas para llevar
Centro Comercial Moctezuma
Chop-suey Chinese
Com é rcio Mineiro
Consolidated Holdings
Die wandrende Kuh
Drachenblut delikatessen
Du monde entier
Eastern Connection
Ernst Handel
Familia arquibaldo
Fissa Fabrica inter. salchichas S..
Folies Gourmandes
Folk och fähb
France Authentication
Franchi S. p..
Frankenversand
Furia bacalhau e Frutos do Mar
Galería del gastr ónomo
Godos cocina típica
Gourmet lanchonetes
Great Lakes food market
Grosella-appsante
...... (See the following )..................................

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.