Collections:
"DECLARE ... CURSOR" - Declaring Cursor Objects in SQL Server
How To Declare a Cursor with "DECLARE ... CURSOR" in SQL Server Transact-SQL?
✍: FYIcenter.com
If you want to use a cursor to represent the result set of a query, you need to define a cursor name with a SELECT sub-statement using the "DECLARE ... CURSOR" statement using the following syntax format:
DECLARE cursor_name CURSOR FOR SELECT ...;
Note that the DECLARE statement will not actually execute the SELECT sub-statement. It only attaches the SELECT sub-statement to the cursor.
A cursor name should be deallocated to free up server resources if the cursor is not needed any more.
The tutorial example below shows you how to declare and deallocate a cursor.
USE FyiCenterData; GO DECLARE fyi_cursor CURSOR FOR SELECT * FROM fyi_links; -- other statements DEALLOCATE fyi_cursor; GO
2016-10-17, 1119👍, 0💬
Popular Posts:
How To Verify Your PHP Installation in MySQL? PHP provides two execution interfaces: Command Line In...
How To Count Duplicated Values in a Column in SQL Server? If you have a column with duplicated value...
What is mscorsvw.exe - Process - Microsoft .NET Framework NGEN in SQL Server? Process mscorsvw.exe i...
How To Convert Numeric Values to Integers in SQL Server Transact-SQL? Sometimes you need to round a ...
How To Convert Character Strings into Numeric Values in SQL Server Transact-SQL? Sometimes you need ...