February 9, 2012 at 2:39 pm
I have the following - and I cannot understand why I receive the error message:
Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.
declare c cursor static local forward_only for
select
[Agent],
[WebAddress]
[ContactPerson],
[Phone1],
[Phone2],
[eMail1],
[eMail2]
[ActionDate],
[Descriptions],
[Phone3],
[Phone4],
[eMail3],
[eMail4],
[CompanyName] from dbo.TEMP
open c
declare
@sourceAgent varchar(1000),
@sourceWebAddress varchar(1000),
@sourceContactPerson varchar(1000),
@sourcePhone1 varchar(1000),
@sourcePhone2 varchar(1000),
@sourceeMail1 varchar(1000),
@sourceeMail2 varchar(1000),
@sourceActionDate varchar(1000),
@sourceDescriptions varchar(1000),
@sourcePhone3 varchar(1000),
@sourcePhone4 varchar(1000),
@sourceeMail3 varchar(1000),
@sourceeMail4 varchar(1000),
@sourceCompanyName varchar(1000),
@sourceUserId uniqueidentifier
fetch next from c into @sourceAgent, @sourceWebAddress, @sourceContactPerson, @sourcePhone1, @sourcePhone2, @sourceeMail1, @sourceeMail2,
@sourceActionDate, @sourceDescriptions, @sourcePhone3, @sourcePhone4, @sourceeMail3, @sourceeMail4, @sourceCompanyName
while @@FETCH_STATUS = 0
begin
select @sourceUserId = UserId from dbo.BUser where upper(UserName) like UPPER(@sourceAgent)
exec dbo.crmProspect_Insert
@WebAddress = @sourceWebAddress,
@ContactPerson = @sourceContactPerson,
@Phone1 = @sourcePhone1,
@eMail1 = @sourceeMail1,
@State = 'Prospect Nou',
@ActionDate = @sourceActionDate,
@NextRecallDate = null,
@Descriptions = @sourceDescriptions,
@Objections = null,
@IsProspect = 1,
@IsClient = 0,
@OwnerUserId = @sourceUserId,
@CompanyName = @sourceCompanyName,
@CUI = null,
@NrOrdRegCom = null,
@CompanyAddress = null,
@BankAccount = null,
@BankId = null,
@BankAgencyName = null,
@Phone2 = @sourcePhone2,
@Phone3 = @sourcePhone3,
@Phone4 = @sourcePhone4,
@eMail2 = @sourceeMail2,
@eMail3 = @sourceeMail3,
@eMail4 = @sourceeMail4,
@CampaignNumber = 0,
@CampaignStatus = 'N/A',
@Comision = NULL
fetch next from c into @sourceAgent, @sourceWebAddress, @sourceContactPerson, @sourcePhone1, @sourcePhone2, @sourceeMail1, @sourceeMail2, @sourceactionDate,
@sourceDescriptions, @sourcePhone3, @sourcePhone4, @sourceeMail3, @sourceeMail4, @sourceCompanyName
end
close c
deallocate c
February 9, 2012 at 2:47 pm
You're missing a comma after WebAddress.
In this case, ContactPerson is taken as a column alias.
-- Gianluca Sartori
February 9, 2012 at 2:54 pm
...and after [eMail2] as well. Spent almost 2 hours trying to figure this out... 😀
Thank you for pointing it out - I am a SQL newbie and I don't have my eyes "SQL set". 🙂
February 9, 2012 at 3:34 pm
In case the script encounters errors and it did what must I add to it so that
1. if an identical line (record) exists already when inserting into table - to avoid duplicate lines - no record should be added?
2. I can UNDO what has been partially done?
3. I can verify in advance that the script will work fully and after this make that actual changes?
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply