I am getting the error "Error Code: Unknown column 't2.FSVisitsToDate' in 'field list' when I run my query but I cannot figure out where my query is wrong. Can anyone point out what I did wrong?
INSERT INTO CMCustomer
(CustomerNumber,
LastName,
FirstName,
Address,
City,
State,
ZIPCode,
PhoneNo,
DriverLicenseNo,
SocialSecNo,
TaxExempt,
ExternalRefNumber,
AuxField,
Comments,
FSLevelNo,
FSDateOpened,
FSLastVisit,
FSVisitsToDate,
FSVisitsThisPeriod,
FSPurchaseToDate,
FSPurchaseThisPeriod,
FSDiscountToDate,
FSDiscountThisPeriod,
FSPointsToDate,
FSPointsThisPeriod,
FSPromoPointsToDate,
FSPromoPointsThisPeriod,
LastUpdated,
Employee)
SELECT t1.CustomerNumber,
t1.LastName,
t1.FirstName,
t1.Address,
t1.City,
t1.State,
t1.ZIPCode,
t1.PhoneNo,
t1.DriverLicenseNo,
t1.SocialSecNo,
t1.TaxExempt,
t1.ExternalRefNumber,
t1.AuxField,
t1.Comments,
t1.FSLevelNo,
t1.FSDateOpened,
t1.FSLastVisit,
t1.FSVisitsToDate,
t1.FSVisitsThisPeriod,
t1.FSPurchaseToDate,
t1.FSPurchaseThisPeriod,
t1.FSDiscountToDate,
t1.FSDiscountThisPeriod,
t1.FSPointsToDate,
t1.FSPointsThisPeriod,
t1.FSPromoPointsToDate,
t1.FSPromoPointsThisPeriod,
t1.LastUpdated,
t1.Employee
FROM cm01process t1
LEFT JOIN CMCustomer t2 ON t2.CustomerNumber = t1.CustomerNumber
ON DUPLICATE KEY UPDATE
t2.FSVisitsToDate = t2.FSVisitsToDate + t1.FSVisitsToDate,
t2.FSVisitsThisPeriod = t2.FSVisitsThisPeriod + t1.FSVisitsThisPeriod,
t2.FSPurchaseToDate = t2.FSPurchaseToDate + t1.FSPurchaseToDate,
t2.FSPurchaseThisPeriod = t2.FSPurchaseThisPeriod + t1.FSPurchaseThisPeriod,
t2.FSDiscountToDate = t2.FSDiscountToDate + t1.FSDiscountToDate,
t2.FSDiscountThisPeriod = t2.FSDiscountThisPeriod + t1.FSDiscountThisPeriod,
t2.FSPointsToDate = t2.FSPointsToDate + t1.FSPointsToDate,
t2.FSPointsThisPeriod = t2.FSPointsThisPeriod + t1.FSPointsThisPeriod,
t2.FSPromoPointsToDate = t2.FSPromoPointsToDate + t1.FSPromoPointsToDate,
t2.FSPromoPointsThisPeriod = t2.FSPromoPointsThisPeriod + t1.FSPromoPointsThisPeriod;
What I am trying to accomplish is to take a file from one of my stores and import it to my database. If it is a new customer I need the row added, and if it is a duplicate customer I need fields updated (points added to the user).