ms-access - 在 Access 查询中的左外连接上为空记录重新调整值

标签 ms-access left-join

我已经尝试了在这种情况下返回值的所有公式,但不断收到错误消息,告诉我我的参数数量错误。这是我的查询:

SELECT [ER Root].[Network Indicator], 
[ER Root].[Prov Indicator], 
[ER Root].[Pos Indicator], 
[ER].[ER Visit]
FROM [ER Root] LEFT JOIN ER ON ([ER Root].[Network Indicator] = ER.[Network Flag]) AND ([ER Root].[Pos Indicator] = ER.[POS Indicator]) AND ([ER Root].[Prov Indicator] = ER.[Category Indicator]);

我试过了:
SELECT [ER Root].[Network Indicator], 
[ER Root].[Prov Indicator], 
[ER Root].[Pos Indicator], 
ISNULL([ER].[ER Visit],0) AS "ER Visit"
FROM [ER Root] LEFT JOIN ER ON ([ER Root].[Network Indicator] = ER.[Network Flag]) AND ([ER Root].[Pos Indicator] = ER.[POS Indicator]) AND ([ER Root].[Prov Indicator] = ER.[Category Indicator

我究竟做错了什么?

最佳答案

Access ' ISNULL函数只接受一个参数并返回一个 bool 值。

如果您想返回 0[ER Visit]为空,您可以使用 Nz在从 Access session 中运行的查询中。

SELECT Nz([ER Visit], 0) AS ER_Visit

注意,我使用了 ER_Visit作为别名,因为如果您尝试将字段名称重新用作别名,数据库引擎可能会提示“循环”引用。

如果您从 Access session 外部(如从经典 ASP 或 .Net)运行查询,Nz功能将不可用。你可以这样做......

SELECT IIf([ER Visit] Is Null, 0, [ER Visit]) AS ER_Visit

关于ms-access - 在 Access 查询中的左外连接上为空记录重新调整值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10178249/

相关文章:

mysql - 计算特定事件之前的事件数

mysql - "Optional"(Mysql查询中的WHERE子句

python - 如何在access数据库中创建小数字段?

mysql - SQL 请求 LEFT JOIN

ms-access - Microsoft Access 是否有 64 位驱动程序?

sql - MS Access 中条件表达式的数据类型不匹配

MySQL从左连接和右连接的结果插入导致内存问题

MySQL 左连接和分组依据

ms-access - 使用多个左连接的 MS Access SQL

sql - 多个 INNER JOIN SQL Access