troubleshooting Question

Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.

Avatar of Chuck Lowe
Chuck Lowe asked on
Microsoft SQL ServerGolangSQL
6 Comments2 Solutions241 ViewsLast Modified:
IN SLQServer 2012 - SQL Server Management Studio

Modifying a stored procedure that has been running forever using one variable for the cursor. I'm trying to use
at least 5 variables for the cursor but get this error when I go over 2 variables.
Using cursors of 1 or 2 variables is no problem no matter what name or what order they are in.
But When trying more than 2 variables I get the error.

Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.

I have tried interchanging all different names and combinations that work together as 2 variables so
I know it's not due to type mismatch. But when I add one that works in combination as 2 variables in the code
as a 3rd variable I get the error. Same goes for 4 or 5 or 6 etc variables.

PROJECT_ID,PROJ_TYPE_ID,CLIENT_ID of TPROJECT are all of type integer in the table

What am I missing?

      BEGIN TRY

            -- Start with return flag set to Success.
            SET @SuccessFlag = 0

            DECLARE @ProjectID      INT = NULL
            DECLARE @ProjTypeID     INT = NULL
            DECLARE @ClientID       INT = NULL
            DECLARE @RecoveryID       INT = NULL
            DECLARE @ProjectName      VARCHAR(255) = NULL

            DECLARE Project_Cursor CURSOR FOR
            SELECT      PROJECT_ID,PROJ_TYPE_ID,CLIENT_ID
            FROM      TPROJECT
            WHERE      PROJECT_ID > 0 AND PROJ_STAT_AVT_ID IN (124, 123, 126, 125, 118)

            -- Open the recordset
            OPEN Project_Cursor;
            -- Start with the first Id
            FETCH NEXT FROM Project_Cursor INTO @ProjectID, @ProjTypeID, @ClientID;

            -- Loop through the recordset
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros