声明 SCROLL 游标并使用其它 FETCH 选项 下例创建一个 SCROLL 游标,使其通过 LAST、PRIOR、RELATIVE 和 ABSOLUTE 选项支持所有滚动能力。USE pubs GO-- Execute the SELECT statement alone to show the -- full result set that is used by the cursor. SELECT au_lname, au_fname FROM authors ORDER BY au_lname, au_fname-- Declare the cursor. DECLARE authors_cursor SCROLL CURSOR FOR SELECT au_lname, au_fname FROM authors ORDER BY au_lname, au_fnameOPEN authors_cursor-- Fetch the last row in the cursor. FETCH LAST FROM authors_cursor-- Fetch the row immediately prior to the current row in the cursor. FETCH PRIOR FROM authors_cursor-- Fetch the second row in the cursor. FETCH ABSOLUTE 2 FROM authors_cursor-- Fetch the row that is three rows after the current row. FETCH RELATIVE 3 FROM authors_cursor-- Fetch the row that is two rows prior to the current row. FETCH RELATIVE -2 FROM authors_cursorCLOSE authors_cursor DEALLOCATE authors_cursor GOau_lname au_fname ---------------------------------------- -------------------- Bennet Abraham Blotchet-Halls Reginald Carson Cheryl DeFrance Michel del Castillo Innes Dull Ann Green Marjorie Greene Morningstar Gringlesby Burt Hunter Sheryl Karsen Livia Locksley Charlene MacFeather Stearns McBadden Heather O'Leary Michael Panteley Sylvia Ringer Albert Ringer Anne Smith Meander Straight Dean Stringer Dirk White Johnson Yokomoto Akiko au_lname au_fname ---------------------------------------- -------------------- Yokomoto Akiko au_lname au_fname ---------------------------------------- -------------------- White Johnson au_lname au_fname ---------------------------------------- -------------------- Blotchet-Halls Reginald au_lname au_fname ---------------------------------------- -------------------- del Castillo Innes au_lname au_fname ---------------------------------------- -------------------- Carson Cheryl
CREATE TABLE [地区资料] (
[地区编号] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[助记码] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[地区名称] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[说明] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
[级别] [int] NOT NULL ,
[末级标识] [bit] NULL CONSTRAINT [DF_地区资料_末级标识] DEFAULT (1),
CONSTRAINT [PK_地区资料] PRIMARY KEY CLUSTERED
(
[地区编号]
) ON [PRIMARY]
) ON [PRIMARY]
GO在VB中,用如下方法打开:iRe.open "select 地区编号,助记码,地区名称,级别,末级标识 from 地区资料 where 停止使用=0",conn
iRe.Filter ="末级标识=1 and ([地区编号] = '%01%'"
http://expert.csdn.net/Expert/topic/2084/2084373.xml?temp=1.856631E-02
下例创建一个 SCROLL 游标,使其通过 LAST、PRIOR、RELATIVE 和 ABSOLUTE 选项支持所有滚动能力。USE pubs
GO-- Execute the SELECT statement alone to show the
-- full result set that is used by the cursor.
SELECT au_lname, au_fname FROM authors
ORDER BY au_lname, au_fname-- Declare the cursor.
DECLARE authors_cursor SCROLL CURSOR FOR
SELECT au_lname, au_fname FROM authors
ORDER BY au_lname, au_fnameOPEN authors_cursor-- Fetch the last row in the cursor.
FETCH LAST FROM authors_cursor-- Fetch the row immediately prior to the current row in the cursor.
FETCH PRIOR FROM authors_cursor-- Fetch the second row in the cursor.
FETCH ABSOLUTE 2 FROM authors_cursor-- Fetch the row that is three rows after the current row.
FETCH RELATIVE 3 FROM authors_cursor-- Fetch the row that is two rows prior to the current row.
FETCH RELATIVE -2 FROM authors_cursorCLOSE authors_cursor
DEALLOCATE authors_cursor
GOau_lname au_fname
---------------------------------------- --------------------
Bennet Abraham
Blotchet-Halls Reginald
Carson Cheryl
DeFrance Michel
del Castillo Innes
Dull Ann
Green Marjorie
Greene Morningstar
Gringlesby Burt
Hunter Sheryl
Karsen Livia
Locksley Charlene
MacFeather Stearns
McBadden Heather
O'Leary Michael
Panteley Sylvia
Ringer Albert
Ringer Anne
Smith Meander
Straight Dean
Stringer Dirk
White Johnson
Yokomoto Akiko au_lname au_fname
---------------------------------------- --------------------
Yokomoto Akiko
au_lname au_fname
---------------------------------------- --------------------
White Johnson
au_lname au_fname
---------------------------------------- --------------------
Blotchet-Halls Reginald
au_lname au_fname
---------------------------------------- --------------------
del Castillo Innes
au_lname au_fname
---------------------------------------- --------------------
Carson Cheryl