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

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?????

ciara_barry123Asked:
Who is Participating?
 
derekkrommConnect With a Mentor Commented:
you're missing @l_original_group_gid in your FETCH at the end of your loop. it should be the last parameter
0
 
derekkrommCommented:
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
 
ciara_barry123Author Commented:
Thanks !!!
It's the little things that'll catch you :-)
cheers for the fast reply!
0
 
derekkrommCommented:
It always helps to have a 2nd person to look at it w/ a fresh mind :)

No problem, glad to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.