Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Databases Programming Interviews:BtrieveClipperData ModelingData StructuresDatabase AdministrationDatabase Administrator (DBA)Database AnalystDatabase DeveloperDB DevelopmentEDI/Data Integration ExpertFirebirdHierarchicalIBM DB2InformixJava DatabaseMariaDBMicrosoft Access DeveloperMongoDBMS SQL ServerMySQL ProgrammingNetworkNoSQLObject RelationalPostgrePostgreSQLProgressRDBMSRelationalSQLSQL AdministratorSQL and PL/SQLSQL Notification ServicesSQL server 2008SSRSStored ProcedureSybaseTeradata
Copyright © 2018. All Rights Reserved
MS SQL Server Interview Question:
How To Fetch the Next Row from a Cursor with a "FETCH" Statement?
Submitted by: AdministratorWhen 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 GlobalGuideLineDatabase;
GO
DECLARE ggl_cursor CURSOR FOR
SELECT * FROM ggl_links;
OPEN ggl_cursor;
FETCH NEXT FROM ggl_cursor;
FETCH NEXT FROM ggl_cursor;
CLOSE ggl_cursor;
DEALLOCATE ggl_cursor;
GO
<pre>id url notes counts time
---- ------------------- ----------- ------- -----
101 globalguideline.com NULL NULL NULL
(1 row(s) affected)
id url notes counts time
---- ----------------------- ----------- ------- -----
102 globalguideline.com/sql Nice site. 8 NULL</pre>
(1 row(s) affected)
Submitted by: Administrator
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 GlobalGuideLineDatabase;
GO
DECLARE ggl_cursor CURSOR FOR
SELECT * FROM ggl_links;
OPEN ggl_cursor;
FETCH NEXT FROM ggl_cursor;
FETCH NEXT FROM ggl_cursor;
CLOSE ggl_cursor;
DEALLOCATE ggl_cursor;
GO
<pre>id url notes counts time
---- ------------------- ----------- ------- -----
101 globalguideline.com NULL NULL NULL
(1 row(s) affected)
id url notes counts time
---- ----------------------- ----------- ------- -----
102 globalguideline.com/sql Nice site. 8 NULL</pre>
(1 row(s) affected)
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.