如何检查两个表中是否存在值

How to check if value exist in two tables

您好,我在网上搜索过,但没有找到我的问题的正确答案。

我有两个 tables GCSALLDATAGCS-RECONCILED。它们都有相同的列,但我只需要关注两个 [Control Number](短文本)和 [NotInDevTrack] (yes/no)

我想搜索 GCSALLDATAGS-RECONCILED 中找到的控制号。如果找到更新记录。

根据我的阅读,使用 DCOUNT 应该可以做到这一点,但想知道它如何循环遍历 table 中的所有记录?

这是我尝试使用它

If DCount("[Control Number]", "GCSALLDATA", "Control Number=" & [GCS_Reconcile].[Control Number]) > 0 Then
    MsgBox ("Control number already in use")
Else
    MsgBox ("Control Number missing add it")
End If

假设我正确理解了你所说的意思:

I want to search GCSALLDATA for the Control Number found in GS-RECONCILED. If it's found Update the record.

您可以使用简单的 update 查询更新 GCSALLDATA 中的记录,在 GS-RECONCILED 中有匹配的控制编号,例如:

update GCSALLDATA t1 inner join GS-RECONCILED t2 on t1.[Control Number] = t2.[Control Number]
set t1.NotInDevTrack = True

假设您希望将匹配的数字的 NotInDevTrack 字段设置为 True (Yes)。