[英]Copy data from one column to another column
I have two database tables belonging to different databases, one empty and one not empty. 我有两个属于不同数据库的数据库表,一个为空,另一个为非空。 I'm transferring data column by column to empty database table.
我正在将数据逐列传输到空数据库表。
First I transferred names like this : 首先,我这样传输名称:
INSERT INTO [newdb].[dbo].[Person] (Name)
SELECT name
FROM [olddb].[dbo].[members]
then I updated a column which is all NULL like this : 然后我更新了一个全部为NULL的列,如下所示:
UPDATE [newdb].[dbo].[Person]
SET IsApproved = 'True'
WHERE IsApproved IS NULL
Now I want to update another null column in new database using the values in the old database. 现在,我想使用旧数据库中的值更新新数据库中的另一个空列。 Can you tell me how I can carry values from old database where all cells are NULL in the new database.
您能告诉我如何从旧数据库中携带新数据库中所有单元格均为NULL的值。 Thanks.
谢谢。
Query is for update only :- 查询仅用于更新:
UPDATE New
SET New.Caption = Old.Caption ,New.Created_By =Old.Created_By
FROM [NewDB].Dbo.Product New
JOIN [OldDB].Dbo.Product Old ON New.Id = Old.Id
WHERE New.Is_Cos IS NULL
You can use JOIN . 您可以使用JOIN 。 Could be something like that:
可能是这样的:
The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.
只要两个表中的列都匹配,INNER JOIN关键字就会从两个表中选择所有行。
UPDATE NewTable
SET N.Col = O.Col
FROM [NewDB].[dbo].[NewTable] N
INNER JOIN [OldDB].[dbo].[OldTable] O
ON N.etc = O.etc
WHERE N.Col IS NULL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.