当相关表中没有匹配时,将字段更新为空值

时间:2013-10-16 06:43:57

标签: ms-access ms-access-2007

我有2个表,如下所示。我需要更新表[ASBUILT_LIST]的[incomming letter contractor]字段,其值为[tblTransmittalls]的

我使用了以下更新查询

UPDATE ASBUILT_LIST INNER JOIN tblTransmittalls 
   ON ASBUILT_LIST.DOC=tblTransmittalls.DocumentNo 
SET ASBUILT_LIST.[incomming letter   contractor] = [tblTransmittalls]![TRANSMITTAL]
    WHERE  ((tblTransmittalls.PurposeofIssue)="FIN"));

现在,如果[DocumentNo]字段没有任何匹配(2个表之间相关),我需要将[包含字母承包商]更新为NULL值。

SET ASBUILT_LIST.[incomming letter contractor] = Null

当匹配时,它会像以前一样更新:

SET ASBUILT_LIST.[incomming letter contractor] = [tblTransmittalls]![TRANSMITTAL]

表格是:

表:ASBUILT_LIST

doc                 incomming letter contractor
------------------  ---------------------------
doc-1000            L-0001
doc-2000            L-0002

表:tblTransmittalls

DocumentNo         TRANSMITTAL      PurposeofIssue
-----------------  ---------------  --------------
DOC-1000           T-0001           FIN
DOC-3000           T-0500           FIN
DOC-4000           T-0600           IFI
DOC-2000           T-0800           IFI

我需要更新的ASBUILT_LIST表,因此在运行更新查询后,它应该是这样的:

doc            incomming letter contractor
-------------  ---------------------------
doc-1000       T-0001   
doc-2000       null

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的描述,DLookup()

应该很容易理解
UPDATE ASBUILT_LIST
SET [incomming letter contractor] = 
    DLookup
        (
            "TRANSMITTAL",
            "tblTransmittalls",
            "DocumentNo = '" & [DOC] & "' AND PurposeofIssue = 'FIN'"
        );