SQL Server:将数据从一列复制到另一列? [英] SQL Server: copy data from one column to another column?

查看:785
本文介绍了SQL Server:将数据从一列复制到另一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有相同列 anomaly_id 的表。我要使用此代码将 anomaly_id 的行从第一个表复制到第二个表

I have two tables with the same column anomaly_id. I want to copy the row of anomaly_id from the first table to the second table using this code

UPDATE amb.anamoly_log_update
SET anamoly_id = t2.anomaly_id
FROM amb.anamoly_log_update t1 
INNER JOIN amb.anomaly_fee t2 ON t1.anamoly_id=t2.anomaly_id

即使在我这样做之后,当 amb中有数据时,它显示0行受影响。 anomaly.fee (源表)

Even after I did that it shows 0 rows affected, when there is data in amb.anomaly.fee (source table)

请帮助

发帖:我只想复制所有 anamoly_id amb.anamoly_fee amb.anamoly_log_update 。我的代码可能是荒谬的。

Comment from post: I just want to copy all the anamoly_id from amb.anamoly_fee to amb.anamoly_log_update. My code might be nonsensical. Please do review it.

推荐答案

要将id从anomaly_fee复制到anamoly_log_update,请使用:

To copy the id from anomaly_fee to anamoly_log_update use :

INSERT INTO anamoly_log_update (anamoly_id)
      SELECT anamoly_id FROM anomaly_fee

这两个列,它看起来像:

with both columns it looks like that:

INSERT INTO anamoly_log_update (anamoly_id,PID)
      SELECT anamoly_id,PID FROM anomaly_fee

这篇关于SQL Server:将数据从一列复制到另一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆