2013-08-21 68 views
4

我已經檢查了好幾次。列數尚未匹配我不斷收到一個錯誤說的提取到語句不符合計數在INTO列表中聲明的變量數量必須與選定列的變量數量相匹配

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.

+1

應該有2'FETCH NEXT'您的查詢,您可以顯示第二個? – Lamak

+0

@Lamak,我剛剛編輯它 – dko

+0

並沒有更多的遊標?,一個調用使用遊標的sp? – Lamak

回答

12

如果你在你之前或列之後逗號的位置一致,你可能已經看準了這一點:

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

這話說SELECT ... RangeLow, RangeHigh AS PostCode1, PostCode2 ...

+0

+1。很好的接收! – Lamak

+0

我只注意到我自己..謝謝... – dko