访问查询以包含所有记录,即使一个字段缺少数据(为 Null)

Posted

技术标签:

【中文标题】访问查询以包含所有记录,即使一个字段缺少数据(为 Null)【英文标题】:Access query to include all records even if one field has missing data (is Null) 【发布时间】:2017-01-27 17:06:17 【问题描述】:

我正在尝试运行查询以包含所有记录。如果其中一个字段为空,它将省略记录。将查询属性中的“输出所有字段”更改为“是”会引入所有字段,但这不是我需要的。我需要所有记录。这是我的 SQL 查询:

SELECT tblBOOK.Concat, tblBOOK.Owner1, tblBOOK.Owner2, 
tblIndustry.[Industry Name], tblOwner1.Points, tblOwner2.Points, 
tblIndustry.[Industry Points], tblBOOK.FILE, tblBOOK.SCORE, 
tblFILE.Points, tblSCORE.Points, tblBOOK.Risk, tblRisk.Points,
[tblOwner1]![Points]+[tblOwner2]![Points]+[Industry Points]+
[tblFILE]!  [Points]+[tblSCORE]![Points]+[tblRisk]![Points] 
AS TtlPoints

FROM tblRisk 
INNER JOIN (tblSCORE 
INNER JOIN (tblFILE 
INNER JOIN ((tblOwner1 
INNER JOIN (tblOwner2 
INNER JOIN tblBOOK 

ON (tblOwner2.Secondary = tblBOOK.Owner2) 
AND (tblOwner2.Primary = tblBOOK.Owner1)) 

ON tblOwner1.Primary = tblOwner2.Primary) 
INNER JOIN tblIndustry 
ON tblBOOK.Industry = tblIndustry.[Industry Name]) 
ON tblFILE.Score = tblBOOK.FILE) 
ON tblSCORE.Score = tblBOOK.SCORE) 
ON tblRisk.Factor = tblBOOK.Risk;

我还尝试将“IsNull”添加到条件中,然后不返回任何记录。

【问题讨论】:

【参考方案1】:

我需要将这些从 INNER JOINS 更改为 LEFT JOINS

SELECT tblBOOK.Concat, tblIndustry.[Industry Name],tblIndustry.[Industry Points],
tblOwner1.Primary, tblOwner1.Points, tblFILE.Score, tblFILE.Points, tblCARD.Score, 
tblCARD.Points, tblRisk.Factor, tblRisk.Points, 
[Industry Points]+[tblOwner1]![Points]+[tblFILE]![Points]+[tblCARD]![Points]+ 
[tblRisk]![Points] 
AS TotalPoints 

FROM ((((tblBOOK 
LEFT JOIN tblIndustry ON tblBOOK.Industry = tblIndustry.[Industry Name])     
LEFT JOIN tblOwner1 ON tblBOOK.Owner1 = tblOwner1.Primary) 
LEFT JOIN tblFILE ON tblBOOK.CSS = tblFILE.Score) 
LEFT JOIN tblCARD ON tblBOOK.CARD = tblCARD.Score) 
LEFT JOIN tblRisk ON tblBOOK.Risk = tblRisk.Factor;

【讨论】:

以上是关于访问查询以包含所有记录,即使一个字段缺少数据(为 Null)的主要内容,如果未能解决你的问题,请参考以下文章

sql查询所有包含中文的数据?

访问报告#Error 文本消息

设置查询以搜索 dojo 数据网格的所有字段

根据字段的开头选择记录?

Oracle 模糊查询 优化

访问帮助以动态确定跨字段的记录日期更改