Critical
The number of variables in a FETCH statement should match the number of columns in the cursor
Rule description
- The number of variables in a FETCH statement should match the number of columns in the cursor
Non-compliant Code Example
DECLARE @FirstName varchar(50);
DECLARE contact_cursor CURSOR FOR
SELECT LastName, FirstName FROM Person.Person
OPEN contact_cursor;
FETCH NEXT FROM contact_cursor
INTO @FirstName; --Non compliant code (Number of variable in Fetch statement is not matching with number of columns in the cursor)
Compliant Code Example
DECLARE @LastName varchar(50), @FirstName varchar(50);
DECLARE contact_cursor CURSOR FOR
SELECT LastName, FirstName FROM Person.Person
OPEN contact_cursor;
FETCH NEXT FROM contact_cursor
INTO @LastName, @FirstName; --Compliant code (Number of variable in Fetch statement is matching with number of columns in the cursor)