== Why is this an issue?

A ``++FETCH++`` statement fails when the number of variables does not match the number of columns selected in the CURSOR definition.


=== Noncompliant code example

[source,sql]
----
DECLARE c1 cursor FOR SELECT FirstName, LastName FROM customer;
OPEN c1;
FETCH NEXT FROM c1 INTO @Name; -- Noncompliant
----


=== Compliant solution

[source,sql]
----
DECLARE c1 cursor FOR SELECT FirstName, LastName FROM customer;
OPEN c1;
FETCH NEXT FROM c1 INTO @FirstName, @LastName;
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Refactor this ``++FETCH++`` to select the same number of columns selected in "xxx".


=== Highlighting

* primary: ``++INTO++`` + column list in ``++FETCH++`` statement
* secondary: ``++SELECT++`` + column list in cursor


'''
== Comments And Links
(visible only on this page)

=== is related to: S3613

=== is related to: S3614

=== on 20 Jul 2017, 15:26:19 Pierre-Yves Nicolas wrote:
According to the Microsoft https://docs.microsoft.com/en-us/sql/t-sql/language-elements/fetch-transact-sql[reference for FETCH]:

____
The number of variables must match the number of columns in the cursor select list.
____


The code can be compiled with no issue, for example in a stored procedure. The following error is raised at runtime:

----
Msg 16924, Level 16, State 1, Line 61
Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.
----

=== on 7 Aug 2017, 15:03:24 Pierre-Yves Nicolas wrote:
\[~massimo.paladin] Why minor? Such code triggers a failure at execution time.

endif::env-github,rspecator-view[]
