使用以下方法将值从一个表覆盖到另一个表 [英] Overwrite values from one table to another using
本文介绍了使用以下方法将值从一个表覆盖到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表,customer和newCustomer.对于特定的列,我想用newCustomer表覆盖客户表的列值.例如:
I have two tables, customer and newCustomer. For specific columns, I want to overwrite the column values of customer table with the newCustomer table. For example :
customer.firstname = newCustomer.firstname
customer.lastname = newCustomer.lastname
**我确实有两个表的匹配ID.
** I do have matching Ids for the two tables.
我可以从编码的角度思考如何做到这一点,但是在考虑使用SQL进行编码时却遇到了困难.
I can think of how to do this in terms of coding, but am having a hard time when thinking of doing this in SQL.
我正在使用Microsoft SQL Server.
I am using Microsoft SQL Server.
不胜感激任何示例或提示.
Would appreciate any examples or hints.
推荐答案
大概是,您具有一些将两个表连接起来的ID.如果是这样,只需使用 join
和 set
:
Presumably, you have some id that connects the two tables. If so, just use join
and set
:
update c
set firstname = nc.firstname,
lastname = nc.lastname
from customer c join
newcustomer nc
on c.customerid = nc.customerid;
这篇关于使用以下方法将值从一个表覆盖到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文