我已将一些数据导入到新的sql表中,并设法将导入的数据更新到正确的表中,但无法更新没有客户编号的记录,我已尝试更新客户编号,但它说它无法更新主要记录。
这是我到目前为止用于更新字段的代码......
update SalBudgetCust
Set
SalBudgetCust.Sales1 = SalBudgetCust_temp.Sales1,
SalBudgetCust.Sales2 = SalBudgetCust_temp.Sales2,
SalBudgetCust.Sales3 = SalBudgetCust_temp.Sales3,
SalBudgetCust.Sales4 = SalBudgetCust_temp.Sales4,
SalBudgetCust.Sales5 = SalBudgetCust_temp.Sales5,
SalBudgetCust.Sales6 = SalBudgetCust_temp.Sales6,
SalBudgetCust.Sales7 = SalBudgetCust_temp.Sales7,
SalBudgetCust.Sales8 = SalBudgetCust_temp.Sales8,
SalBudgetCust.Sales9 = SalBudgetCust_temp.Sales9,
SalBudgetCust.Sales10 = SalBudgetCust_temp.Sales10,
SalBudgetCust.Sales11 = SalBudgetCust_temp.Sales11,
SalBudgetCust.Sales12 = SalBudgetCust_temp.Sales12
From
SalBudgetCust_temp where SalBudgetCust.Customer = SalBudgetCust_temp.Customer
如果客户记录不存在已经从另一个表中填充然后包含相应的销售数据,是否有人能够提供一些说明?
答案 0 :(得分:0)
尝试SELECT INTO
语句,如下所示,插入客户不存在的记录:
SELECT * INTO SalBudgetCust FROM SalBudgetCust_temp WHERE NOT EXISTS (SELECT Customer FROM SalBudgetCust WHERE Customer = SalBudgetCust_temp.Customer)
此SO答案也可以帮助您解决问题:
How to avoid duplicates in INSERT INTO SELECT query in SQL Server?