1

我在 MS Access 中有查询产生正确的记录结果,但 Access 拒绝将查询作为删除查询运行?
谁能帮我重写这个查询以在访问中运行。

Delete Table_A.*
FROM (SELECT Table_A.Main_RecID, Table_A.Fld_Unique_ID, Table_A.Actiontaken FROM Table_A 
WHERE Table_A.Actiontaken="MainRecord deleted")  AS Tmp_B 
LEFT JOIN Table_A ON Tmp_B.Main_RecID=Table_A.Main_Recid
WHERE (((Table_A.Actiontaken)<>"MainRecord deleted"));

如果“删除”被选择替换,或者我要求查看数据表,则查询会产生我所期望的结果。这是表中具有相同 Main_RecID 与 Actiontaken 字段 =“MainRecord deleted”但其 Actiontaken 字段不等于“MainRecord deleted”的记录的列表。

Access 响应消息“无法从指定的表中删除”。

4

1 回答 1

0

我从这些数据开始Table_A...

Fld_Unique_ID Main_RecID Actiontaken
            1          1 MainRecord deleted
            2          1 
            3          2 MainRecord deleted
            4          2 something else
            5          3 something else

注意Actiontaken第二行为 Null(其中Fld_Unique_ID= 2)。

执行DELETE下面的语句会将该数据保留在表中。

Fld_Unique_ID Main_RecID Actiontaken
            1          1 MainRecord deleted
            3          2 MainRecord deleted
            5          3 something else
DELETE
FROM Table_A
WHERE
    (
           Actiontaken<>'MainRecord deleted'
        OR Actiontaken Is Null
    )
    AND
    (
        DCount("*", "Table_A",
            "Main_RecID = " & Main_RecID
            & " AND Actiontaken='MainRecord deleted'") > 0
    );

如果这不是您所追求的,请向我们展示之前和之后的示例数据DELETE

于 2012-07-01T04:12:46.337 回答