Microsoft Access 和 SQL - 在 table.2 上不存在记录时更新 table.1 值

Microsoft Access and SQL - Update table.1 value when the record does not exist on table.2

我在使用下面的代码时遇到了一些问题。当 Upload.Invoice table 上没有匹配的发票时,我想将 Unprocessed/Unapproved table 的状态字段更新为 2,当它为 7 和发票时字段不为空。

我已经尝试了下面的 SQL 并且它没有更新符合条件的值。对于我的测试,应该有 4 个更新和 0 个正在完成。我通常使用设计视图,但不确定代码中哪里出错了。

UPDATE 
    [Unprocessed/Unapproved TC], 
    Upload 
SET 
    [Unprocessed/Unapproved TC].Status = 2, 
    [Unprocessed/Unapproved TC].[Resolution Date] = Date()
WHERE 
    (([Unprocessed/Unapproved TC].Status)=7) 
    AND 
    (([Unprocessed/Unapproved TC].Invoice) Is Not Null) 
    AND 
    (Not Exists 
        (
            SELECT 
                * 
            FROM 
                [Unprocessed/Unapproved TC]
            WHERE 
                [Unprocessed/Unapproved TC].Invoice = [Upload].Invoice
        )
    );

我认为你应该在 not exists 子句中查询上传 table 并且在 update 子句中只引用你想要更新的 table ,所以试试这个(但要确定在 运行 之前进行备份):

UPDATE 
    [Unprocessed/Unapproved TC]     
SET 
    [Unprocessed/Unapproved TC].Status = 2, 
    [Unprocessed/Unapproved TC].[Resolution Date] = Date()
WHERE 
    (([Unprocessed/Unapproved TC].Status)=7) 
    AND 
    (([Unprocessed/Unapproved TC].Invoice) Is Not Null) 
    AND 
    (Not Exists 
        (
            SELECT 
                * 
            FROM 
                [Upload]
            WHERE 
                [Unprocessed/Unapproved TC].Invoice = [Upload].Invoice
        )
    );