我的查询从其他两个查询中提取总费用,然后将这些查询相加以生成作业总成本。我的问题是,当输入作业并且查询在后台运行时,依赖于作业意味着一个字段可能不包含任何成本信息。我相信这是因为这些空单元格总数不能正确填充,因此需要用£0替换空白。
https://i.stack.imgur.com/zcnk2.png
https://i.stack.imgur.com/OWJdX.png
SELECT tblMaintenanceLog.LogID, Last(QIntTotals.IntTotal) AS LastOfIntTotal, Last(QExtPartsTotalsComp.SumOfSumOfEXTPCost) AS LastOfSumOfSumOfEXTPCost, [IntTotal]+[SumOfSumOfEXTPCost] AS Expr1
FROM (tblMaintenanceLog LEFT JOIN QIntTotals ON tblMaintenanceLog.LogID = QIntTotals.INTJobID) LEFT JOIN QExtPartsTotalsComp ON tblMaintenanceLog.LogID = QExtPartsTotalsComp.EXTPJobID
GROUP BY tblMaintenanceLog.LogID, [IntTotal]+[SumOfSumOfEXTPCost]
ORDER BY tblMaintenanceLog.LogID;
我尝试过if语句用空格替换空格以及Nz函数而没有任何效果。但是,我可能只是输错了,因为我对VBA和SQL还是比较新的所以任何帮助都会非常感激!
谢谢大家:)
答案 0 :(得分:0)
在这种情况下,您可以使用COALESCE。
SELECT tblMaintenanceLog.LogID , COALESCE(NULLIF(Last(QIntTotals.IntTotal),''),0) AS LastOfIntTotal, Last(QExtPartsTotalsComp.SumOfSumOfEXTPCost) AS LastOfSumOfSumOfEXTPCost, [IntTotal]+[SumOfSumOfEXTPCost] AS Expr1
FROM (tblMaintenanceLog LEFT JOIN QIntTotals ON tblMaintenanceLog.LogID = QIntTotals.INTJobID) LEFT JOIN QExtPartsTotalsComp ON tblMaintenanceLog.LogID = QExtPartsTotalsComp.EXTPJobID
GROUP BY tblMaintenanceLog.LogID, [IntTotal]+[SumOfSumOfEXTPCost]
ORDER BY tblMaintenanceLog.LogID;
答案 1 :(得分:0)
我有答案!!
Iif(Last(QIntTotals.IntTotal)为null,0,Last(QIntTotals.IntTotal))
我不能非常感谢你的帮助ppijnenburg!在你向我展示之前,我没有意识到如何在SQL中正确添加内容!你救了我很多心痛!!!!谢谢:))