问题描述
我有两个表,customer和newCustomer。对于特定的列,我想用newCustomer表覆盖客户表的列值。例如:
customer.firstname = newCustomer.firstname customer.lastname = newCustomer.lastname
**我确实有两个表的匹配ID。
我可以从编码的角度思考如何做到这一点,但是在考虑使用sql时却很难。
我正在使用Microsoft sql Server。
不胜感激任何示例或提示。
解决方法
大概,您有一些用于连接两个表的ID。如果是这样,只需使用join
和set
:
update c
set firstname = nc.firstname,lastname = nc.lastname
from customer c join
newcustomer nc
on c.customerid = nc.customerid;