从2个不同的表中获取同一个人 [英] Get same person from 2 different tables
问题描述
我有2张桌子
表1:
======
ID名称EmpID
== ==== =====
1 Dan 12
2 Isaro 13
Table2 :
======
ID名称EmpID
== ==== ======
1 Muhi Dan NULL
2 Johanna Isaro NULL
我想从table1插入table2的EmpID但是我想要检查表2中是否存在来自表1的Dan,Isaro。如果是这样,那么它可以从table1向table2插入相同的EmpID。
正如你在表2中看到的那样,muhi Dan意味着Dan存在于table2中,意味着它应该插入它。
如何执行此操作?
I have 2 tables
Table1:
======
ID Name EmpID
== ==== =====
1 Dan 12
2 Isaro 13
Table2:
======
ID Name EmpID
== ==== ======
1 Muhi Dan NULL
2 Johanna Isaro NULL
I want to insert into table2 the EmpID from table1 but I want to check if Dan, Isaro from the table 1 exist in the table2. If so then it can insert into table2 the same EmpID from table1.
As u can see in the table2 there is muhi Dan means Dan exists in the table2, means then it should insert this.
How to perform this?
推荐答案
UPDATE Table2
SET EmpID = t1.EmpID
FROM
Table2 t2
INNER JOIN
Tabel1 t1
ON
t2.Name LIKE '%' + t1.Name
这样可以确保table2中的名称以table1中的名称结尾。
This makes sure that the name in table2 ends with the name in table1.
这篇关于从2个不同的表中获取同一个人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!