访问2013查询将null替换为0不起作用?

时间:2017-03-26 03:33:08

标签: sql database vba access

我尝试创建一个插入一些公式的查询,但如果公式中涉及的单元格中有任何NULL,则该结果没有结果。我尝试将NULL替换为0(无需显示数字0,只需要一个值,以便公式可以使用)SELECT IIF(ISNULL([field]), 0, [field]) FROM [table],但我不要&# 39;知道如何在SQL视图中正确编写它。这是整个SQL代码:

SELECT [LISTING MASTER].Broker, [LISTING MASTER].Type,
[LISTING MASTER].[TransID], [LISTING MASTER].ACTIVE, 
[LISTING MASTER].[CANCELLED - CLIENT], [LISTING MASTER].[CANCELLED - TEAM], 
[LISTING MASTER].EXPIRED, [LISTING MASTER].[OFF MARKET], 
[LISTING MASTER].PENDING, [LISTING MASTER].[SOLD - EXTERNAL], 
[LISTING MASTER].[SOLD - INTERNAL], [LISTING MASTER].UNSIGNED, 
[ACTIVE]/[TransID] AS active1, [CANCELLED - CLIENT]/([TransID]-[ACTIVE]) AS CC2, 
[CANCELLED - TEAM]/([TransID]-[ACTIVE]) AS CT3, [EXPIRED]/([TransID]-[ACTIVE]) AS expired4
FROM [LISTING MASTER];

如何将所有NULL更改为0?更具体地说,我需要[ACTIVE]/[TransID] AS active1, [CANCELLED - CLIENT]/([TransID]-[ACTIVE]) AS CC2, [CANCELLED - TEAM]/([TransID]-[ACTIVE]) AS CT3, [EXPIRED]/([TransID]-[ACTIVE]) AS expired4这一部分有效。 如果有人可以修复它并粘贴整个代码,以便我可以将其粘贴到我的SQL视图中,那将非常感谢!我几乎不知道编码...非常感谢。

What the query looks like

Design view

1 个答案:

答案 0 :(得分:2)

您也可以使用Nz()函数替代IIF:

Nz([field], 0)

请参阅this info关于Nz()。