Collections:
"FETCH" - Fetching the Next Row from a Cursor in SQL Server
How To Fetch the Next Row from a Cursor with a "FETCH" Statement in SQL Server Transact-SQL?
✍: FYIcenter.com
When the result set is ready in a cursor, you can use a FETCH statement to retrieve one row from the result set in the same format as a SELECT statement. The FETCH statement has the following formats:
FETCH NEXT FROM cursor_name; FETCH PRIOR FROM cursor_name; FETCH FIRST FROM cursor_name; FETCH LAST FROM cursor_name; FETCH ABSOLUTE n FROM cursor_name; FETCH RELATIVE n FROM cursor_name;
The tutorial exercise below shows you how FETCH statements are used to retrieve the first row and the second row back from a cursor:
USE FyiCenterData; GO DECLARE fyi_cursor CURSOR FOR SELECT * FROM fyi_links; OPEN fyi_cursor; FETCH NEXT FROM fyi_cursor; FETCH NEXT FROM fyi_cursor; CLOSE fyi_cursor; DEALLOCATE fyi_cursor; GO id url notes counts time ---- ------------------ ----------- ------- ----- 101 dev.fyicenter.com NULL NULL NULL (1 row(s) affected) id url notes counts time ---- ------------------ ----------- ------- ----- 102 dba.fyicenter.com Nice site. 8 NULL (1 row(s) affected)
⇒ "FETCH" - Transferring Data from Cursors to Variables in SQL Server
⇐ "OPEN" - Executing the Query of a Cursor in SQL Server
2016-10-17, 1788🔥, 0💬
Popular Posts:
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...
How To Drop a Stored Procedure in Oracle? If there is an existing stored procedure and you don't wan...
How To Provide Default Values to Function Parameters in SQL Server Transact-SQL? If you add a parame...
What are binary literals supported in SQL Server Transact-SQL? Binary literals in Transact-SQL are s...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...