fetch

Description

Returns a row or a set of rows from a cursor result set.

Syntax

fetch cursor_name [ into fetch_target_list ]

Parameters

cursor_name

the name of the cursor

into fetch_target_list

is a comma-separated list of parameters or local variables into which cursor results are placed. The parameters and variables must be declared prior to the fetch.

Examples

Example 1

Returns a row of information from the cursor result set defined by the authors_crsr cursor:

fetch authors_crsr

Example 2

Returns a row of information from the cursor result set defined by the pubs_crsr cursor into the variables @name, @city, and @state:

fetch pubs_crsr into @name, @city, @state

Usage


Restrictions


Cursor position


Determining the number of rows fetched


Getting information about fetches

Standards

ANSI SQL – Compliance level: Entry-level compliant.

The use of variables in a target list and fetch of multiple rows are Transact-SQL extensions.

Permissions

fetch permission defaults to all users.

See also

Commands declare cursor, open, set