iif 语句可以产生另一个字段的值吗?

Can an iif statement produce the value of another field?

我的 MS 访问查询中有一个 Iif 语句没有产生结果。我要求它查看一个字段的值,如果它是空白的,则显示另一个字段的值,如果不是空白,则显示它的值

采购:IIf([NewPurchasePrice]="",[PurchasePrice],[NewPurchasePrice])

可能 NewPurchasePrice 不是空字符串而是 Null。您可以使用 IsNull(NewPurchasePrice) 对其进行测试。如果你想确保对 Null 和空字符串都进行测试,你可以写 Nz(NewPurchasePrice)=""Nz()Null 转换为与类型的默认值兼容的特殊值 Empty。对于 Integer,例如 Nz(Null) = 0,对于字符串 Nz(Null) = "",等等

对于类型可能是DecimalDouble的价格,只写

 Purchase: IIf(IsNull([NewPurchasePrice]),[PurchasePrice],[NewPurchasePrice])