Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The number of variables declared in the INTO list must match that of selected columns [duplicate]

I have checked over this several times. The column count matches yet I keep getting an error saying the fetch into statement does not match the count

declare cur_range CURSOR FOR
SELECT 
GroupID,
OddEven,
RangeLow,
RangeHigh
PostCode1,
PostCode2,
ID,
OldPrimaryID,
ThFareID
FROM tmpNewPrimaryRange;    

OPEN cur_range

FETCH NEXT FROM cur_range
into
 @cur_GroupID
 , @cur_OddEven
 , @cur_RangeLow
 , @cur_RangeHigh
 , @cur_PostCode1
 , @cur_PostCode2
 , @cur_ID
 , @cur_OldPrimaryID
 , @cur_ThFareID

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

like image 913
dko Avatar asked Aug 21 '13 16:08

dko


1 Answers

If you were consistent in your placement of commas either before or after columns, you might have spotted this:

declare cur_range CURSOR FOR
SELECT 
GroupID,
OddEven,
RangeLow,
RangeHigh    --- <-- ******* NO COMMA HERE ******
PostCode1,
PostCode2,
ID,
OldPrimaryID,
ThFareID

This is saying SELECT ... RangeLow, RangeHigh AS PostCode1, PostCode2 ...

like image 185
Aaron Bertrand Avatar answered Oct 13 '22 01:10

Aaron Bertrand