declare cur cursor for select * from openrowset('sqloledb','trusted_connection=yes','master..sp_columns ''table1''') open cur fetch next from cur while @@fetch_status = 0 begin ... /*对结果集进行处理*/ fetch next from cur end close cur deallocate cur
USE pubs GO DECLARE authors_cursor CURSOR FOR SELECT au_lname FROM authors WHERE au_lname LIKE "B%" ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch. FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch. WHILE @@FETCH_STATUS = 0 BEGIN -- This is executed as long as the previous fetch succeeds. FETCH NEXT FROM authors_cursor ENDCLOSE authors_cursor DEALLOCATE authors_cursor GOau_lname ---------------------------------------- Bennet au_lname ---------------------------------------- Blotchet-Halls au_lname ----------------------------------------
open cur
fetch next from cur
while @@fetch_status = 0
begin
... /*对结果集进行处理*/
fetch next from cur
end
close cur
deallocate cur
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_lname FROM authors
WHERE au_lname LIKE "B%"
ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch.
FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor
GOau_lname
----------------------------------------
Bennet
au_lname
----------------------------------------
Blotchet-Halls
au_lname
----------------------------------------