Home >> FAQs/Tutorials >> SQL Server FAQ
SQL Server FAQ - "OPEN" - Executing the Query of a Cursor
(Continued from previous topic...)
How To Execute the Cursor Queries with "OPEN" Statements?
Once a cursor is declared, you need to execute the query attached to the cursor
so that the result set returned from the query can be accessed through the cursor.
To execute the cursor query, you should use the OPEN statement as in this format:
When you are done with using the result set attached to a cursor,
you should close the result set to free up server resources.
The tutorial example below shows you how to open and close a cursor:
DECLARE fyi_cursor CURSOR FOR
SELECT * FROM fyi_links;
-- result set is ready to use
-- other statements
(Continued on next topic...)
- What Are Cursors?
- How To Declare a Cursor with "DECLARE ... CURSOR"?
- How To Execute the Cursor Queries with "OPEN" Statements?
- How To Fetch the Next Row from a Cursor with a "FETCH" Statement?
- How To Transfer Data from a Cursor to Variables with a "FETCH" Statement?
- How To Loop through the Result Set with @@FETCH_STATUS?
- How To Declare and Use Cursor Variables?
- How To Create a Scrollable Cursor with the SCROLL Option?
- How To Create a Dynamic Cursor with the DYNAMIC Option?