?
Solved

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

Posted on 2007-08-03
4
Medium Priority
?
1,145 Views
Last Modified: 2013-11-05
I have a cursor in the following code:
DECLARE EOBMaxCursor CURSOR FOR
      SELECT       distinct tpc.contact_gid,
            tpc.member_id,
            tgfm.highest_group_for_max_nonortho,      
            tpc.group_gid
      FROM #temp_payment_members tpc INNER JOIN #temp_groups_for_maximum tgfm
      ON (tpc.group_gid = tgfm.group_gid)
      WHERE tgfm.group_for_max_for_nonortho = 'Y'
      ORDER BY tpc.contact_gid,
            tpc.member_id,
            tgfm.highest_group_for_max_nonortho,
            tpc.group_gid

OPEN EOBMaxCursor

FETCH NEXT FROM EOBMaxCursor INTO @l_contact_gid, @l_member_id, @l_group_gid, @l_original_group_gid


WHILE @@fetch_status = 0
BEGIN


      INSERT INTO  #temp_group_gids_for_max
            (group_gid)
      EXEC prADJCMNGetGroupGids @l_group_gid, 'TabularRecordSET', @l_member_id, '', @l_contact_gid, 0

            
      INSERT INTO  temp_groups_for_max_by_patient
      (contact_gid ,
      member_id ,
      group_gid,
      original_group_gid )
      SELECT @l_contact_gid,
            @l_member_id,
            group_gid,
            @l_original_group_gid
      FROM #temp_group_gids_for_max
      
      
      TRUNCATE TABLE #temp_group_gids_for_max
      
      FETCH NEXT FROM EOBMaxCursor INTO @l_contact_gid, @l_member_id, @l_group_gid


END --of EOBMaxCursor
CLOSE EOBMaxCursor
DEALLOCATE EOBMaxCursor

Every time I run this I'm getting the following error:
Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.

Any suggestions?????

0
Comment
Question by:ciara_barry123
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 2000 total points
ID: 19624568
you're missing @l_original_group_gid in your FETCH at the end of your loop. it should be the last parameter
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 19624570
FETCH NEXT FROM EOBMaxCursor INTO @l_contact_gid, @l_member_id, @l_group_gid

should be

FETCH NEXT FROM EOBMaxCursor INTO @l_contact_gid, @l_member_id, @l_group_gid, @l_original_group_gid
0
 

Author Comment

by:ciara_barry123
ID: 19624587
Thanks !!!
It's the little things that'll catch you :-)
cheers for the fast reply!
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 19624595
It always helps to have a 2nd person to look at it w/ a fresh mind :)

No problem, glad to help
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question