[英]IS NULL doesn't work
I have a table like the one above with the two left columns (Both of them are integer) and I added to this table two more fields: 我有一个像上面的表一样的表,左两列(它们都是整数),我在表中又增加了两个字段:
Table1: 表格1:
Asset_Value Contract_Value
-------------------------------
0 NULL
NULL 200
0 NULL
And the query: 和查询:
Select
Asset_Value, Contract_Value,
Case
when Asset_Value is null
then 1
else 0
end As Ind_ForNullA,
Case
when Contract_Value is null
then 1
else 0
end As IndForNullC
from
table1
However, I get strange results: 但是,我得到了奇怪的结果:
Asset_Value Contract_Value Ind_ForNullA IndForNullC
----------------------------------------------------
0 NULL 1 1
NULL 200 0 0
0 NULL 0 1
Update : Never Mind. 更新:没关系。 Damm comma has been forgetten.
Damm逗号已被遗忘。
尝试使用''空字符串而不是null。
Why are you bothering to define something as NULL--which is appropriate--but, in this case or that one, changing it to one or zero (an attempt at Boolean, I imagine)--which is inappropriate? 为什么要麻烦地将某些东西定义为NULL(这是适当的),但是在这种情况下,将其更改为1或零(我想尝试使用布尔值),这不合适吗?
What will you do next: decide that, in a third report, you want to have a REAL boolean that displays TRUE or FALSE? 接下来要做什么:在第三份报告中,确定您想要一个显示TRUE或FALSE的REAL布尔值?
Go with NULL consistently, throughout the entire application, everywhere, or don't. 在整个应用程序中,无论何时何地都始终使用NULL。 However, DO NOT MIX AND MATCH PARADIGMS and expect consistent results.
但是,请勿混合和匹配天堂,并希望获得一致的结果。 Also, try not to rely upon CASE: there's very, very legitimate reason to depend upon that--especially for something as simplistic as what you're doing.
另外,请尽量不要依赖CASE:有非常非常合理的理由要依赖CASE,尤其是要像您所做的事情那样简单。
FYI, the only reason I can conceive why you would want this "indicator" field is so that you can test whether INDICATOR_A = 1. However, since you can test ASSET IS NULL, why even bother? 仅供参考,我可以理解为什么想要这个“指标”字段的唯一原因是可以测试INDICATOR_A =1。但是,由于您可以测试ASSET IS NULL,所以为什么还要打扰呢? NEVER introduce extraneous mechanisms when there is no overpowering reason to do so.
在没有压倒一切的理由时,切勿引入无关的机制。
Try to use the function ASCII 尝试使用ASCII功能
ASCII ( character_expression )
ASCII(character_expression)
Using this function you can understand what is the really character in the column Asset_Value: for example NULL value must have ASCII code: '00' Table with character ASCII code 使用此功能,您可以了解什么是Asset_Value列中的真正字符:例如NULL值必须具有ASCII码:'00' 带有字符ASCII码的表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.