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 )..................................