DF025: The FETCH statement is used without the INTO clause.
Last modified: May 28, 2025
The topic describes the DF025 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
The FETCH statement is used without the INTO clause.
Description
For the FETCH statements, it is recommended to specify local variables to place the data from the columns of a fetch to.
Additional information
Omitting the INTO clause can result in data being fetched but not stored anywhere, leading to potential loss of data or incorrect results. Therefore, it’s important to always include the INTO clause in FETCH statements to ensure proper handling of fetched data and to avoid unexpected behavior in SQL queries.
Noncompliant code example
DECLARE cur CURSOR LOCAL FOR
SELECT CustomerID FROM dbo.Customer
FETCH NEXT FROM cur
Compliant solution
DECLARE cur CURSOR LOCAL FORWARD_ONLY FOR
SELECT CustomerID FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId
DEALLOCATE cur
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.