SQL Null设置为零以添加 [英] SQL Null set to Zero for adding
本文介绍了SQL Null设置为零以添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT Column1,Column2,Column3 + Column4 AS [Added values]
FROM Table
其中Column3或Column4可能为null。在这种情况下,我想要将零视为零(所以 4 + null = 4,null + null = 0
)
关于如何实现这一点的任何建议?
解决方案
由于Access中的ISNULL是一个布尔函数(一个参数) ,使用如下:
SELECT Column1,Column2,IIF(ISNULL(Column3),0,Column3)+ IIF (Column4),0,Column4)AS [已添加值]
FROM表
I have a SQL query (MS Access) and I need to add two columns, either of which may be null. For instance:
SELECT Column1, Column2, Column3+Column4 AS [Added Values]
FROM Table
where Column3 or Column4 may be null. In this case, I want null to be considered zero (so 4 + null = 4, null + null = 0
).
Any suggestions as to how to accomplish this?
解决方案
Since ISNULL in Access is a boolean function (one parameter), use it like this:
SELECT Column1, Column2, IIF(ISNULL(Column3),0,Column3) + IIF(ISNULL(Column4),0,Column4) AS [Added Values]
FROM Table
这篇关于SQL Null设置为零以添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文