我在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"));
如果将“删除”替换为选择或我要求数据表视图,则查询会产生我期望的结果。这是表中与Recordtaken字段=“MainRecord已删除”的记录具有相同Main_RecID的记录列表,但没有将其Actiontaken字段等于“MainRecord deleted”。
Access响应消息“无法从指定的表中删除”。
答案 0 :(得分: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
在第二行是空的(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
之前和之后向我们展示样本数据。