1

当我使用子查询作为变量之一运行查询时,我收到错误 3021(“未找到当前记录”,但有记录可找到)。

这是代码:

SELECT thefieldsiwant, etc.etc., 

(SELECT directory.person_name FROM directory INNER JOIN doc ON doc.entity_to=directory.entity_id) AS receiver,

(SELECT directory.person_name FROM directory INNER JOIN doc ON doc.entity_from=directory.entity_id) AS sender

FROM doc;

entity_id 是表“目录”的主键。

entity_to 和 entity_from 是表“doc”的外键。

基本上,如果他是文档的发件人(以及另一个人的姓名作为文档的接收者),我只是希望该人的姓名出现,而不是这两个特定人的 ID。

4

1 回答 1

0

尝试将所有内容都放入 FROM 中,如下面的代码。此外,如果您使用以下某些代码,则应确保如果 SELECT 列之一为 NULL,则 Access 返回一个替换值:

select  doc.documentname, 
        reciever.person_name, 
        sender.person_name 
from 
doc 
LEFT JOIN
    ((SELECT directory.person_name, doc.entity_to FROM directory INNER JOIN doc ON doc.entity_to=directory.entity_id) AS receiver on doc.entity_to = receiver.entity_to)
LEFT JOIN   
    ((SELECT directory.person_name, doc.entity_from FROM directory INNER JOIN doc ON doc.entity_from=directory.entity_id) AS sender on doc.entity_from = sender.entity_from)
where dir.entity_id = '[enter id for user]'
于 2013-10-01T03:40:42.193 回答