-3

Cursorfetch:INTO 列表中声明的变量数量必须与所选列的数量相匹配。

请用下面的代码帮助我。我收到错误 Cursorfetch:INTO 列表中声明的变量数量必须与所选列的数量匹配。我花了一天时间试图找出原因,但它不起作用。

非常感谢

  -- declare cursor variables
  declare 
  @PKCustomerRecord int, 
  @Agent varchar(100), 
  @CallBackDateTime datetime,
  @Title varchar(15), 
  @Forename varchar(30), 
  @Surname varchar(30), 
  @Address1 varchar(50),
  @Address2 varchar(50), 
  @Address3 varchar(50), 
  @Address4 varchar(50), 
  @Address5 varchar(50), 
  @PostCode varchar(10), 
  @ContactNumber varchar(16), 
  @Telephone2 varchar(16), 
  @DOB datetime, 
  @Source varchar(30), 
  @list_id int, 
  @user_group varchar(8), 
  @campaign_id varchar(8), 
  @ViciDialID int, 
  @PKUsers int, 
  @LeadId int, 
  @ViciUser varchar(20), 
  @Comments varchar(max) 



  -- declare cursor
declare csr cursor for 
  select 
        ViciDialID, PKUsers, CallBackDateTime, CallBackDateTime, [user] as Agent,
        ci.PKCustomerRecord, ci.Title, ci.Forename, ci.Surname,
        ci.Address1, ci.Address2, ci.Address3, ci.Address4, ci.Address5, ci.PostCode,
        ci.DOB, case when ci.Source = 'CB' then ci.ContactLoadSource else ci.Source end as Source,
        cb.ContactNumber,
        case when cb.ContactNumber COLLATE DATABASE_DEFAULT <> ci.Telephone1 then ci.Telephone1 
        when cb.ContactNumber COLLATE DATABASE_DEFAULT <> Telephone2 then Telephone2 end as Telephone2,
        case 
        when ci.Source = 'SASurvey' then 8890 
        when ci.Source = 'AAR' then 8891
        when ci.Source = 'CB' then 8893
        when ci.Source = 'RTA' then 8894
        when ci.Source = 'Verve Survey' then 8895
        when ci.Source = 'Unregistered' then 8892 end as list_id, user_group, campaign_id,
        cb.Comments
  from CAGSQL.CallCenter.dbo.CallBacks cb
  join #ViciDialData u on cb.UserFK = u.PKUsers
  join CAGSQL.ConsumerCare.dbo.ContactInfo ci on cb.ContactInfoFK = ci.PKCustomerRecord  
  where PoolFK = '173'
  and CallBackDateTime > getdate()  
  and UpdatedDate is null 
  and Source in ('AB','AR','CB','TR','YY','AA')
  and DataLength(Comments) < 255
  and UpdatedDate is null 


  open csr
  -- fetch first record
  fetch next from csr into 
  @PKCustomerRecord, 
  @Agent, 
  @CallBackDateTime, 
  @Title, 
  @Forename, 
  @Surname, 
  @Address1, 
  @Address2, 
  @Address3, 
  @Address4, 
  @Address5, 
  @PostCode, 
  @ContactNumber, 
  @Telephone2, 
  @DOB, 
  @Source, 
  @list_id, 
  @user_group, 
  @campaign_id,
  @ViciDialID,
  @Comments, 
  @ViciUser, 
  @LeadId, 
  @PKUsers 

  while @@fetch_status = 0
  begin 



        if left(@ContactNumber, 1) = '0' set @ContactNumber = substring(@ContactNumber,2,11)
        if left(@Telephone2, 1) = '0' set @Telephone2 = substring(@Telephone2,2,11)

        insert into VICI...vicidial_list
        (status, entry_date, status, [user],  list_id, gmt_offset_now, called_since_last_reset, phone_code, phone_number, alt_phone, title, 
        first_name, last_name, address1, address2, address3, city, postal_code, date_of_birth, entry_list_id, source_id)
        values
        ('NEW', getdate(), 'CBHOLD', '', @list_id, 1, 'N', '44', @ContactNumber, @Telephone2, @Title, 
        @Forename, @Surname, @Address1, @Address2, @Address3, @address4, @PostCode, @DOB, @list_id, @Source)

        -- get the ID of the record just inserted
        select @LeadId = max(lead_id) from VICI...vicidial_list

        -- insert the callback record into Vici dial
        insert into VICI...vicidial_callbacks
        (lead_id, list_id, campaign_id, status, entry_time, callback_time, modify_date, [user], recipient, 
        comments, user_group, lead_status)
        values 
        (@LeadId, @list_id, 'CCWarm', 'ACTIVE', getdate(), @CallBackDateTime, getdate(), @ViciUser, 'USERONLY', 
        @Comments, 'CCWarm', 'CALLBK')


        -- fetch next record from CURSOR
        fetch next from csr into @PKCustomerRecord, @Agent, @CallBackDateTime, @Title, @Forename, @Surname, 
        @Address1, @Address2, @Address3, @Address4, @Address5, @PostCode, @ContactNumber, @Telephone2, @DOB, @Source, @list_id, @user_group, @campaign_id,
        @ViciDialID, @PKUsers, @Comments

  end -- END OF CURSOR LOOP

  close csr
  deallocate csr
4

2 回答 2

2

错误描述非常清楚。您在SELECT语句中指定了 23 个字段,但在fetch next from csr into.

此外,您的字段和变量搞砸了。你真的想把变量,这cb.Comments是?@PKUsersINT

于 2013-10-18T09:54:10.653 回答
0

我认为您已经选择了CallBackDateTime列两次,所以我与提取中的列数不匹配。

此外,您当前的选择有 23 列(如果我的计数是正确的),而您的 fetch 有 24 列。

于 2013-10-18T09:59:29.713 回答