本文介绍了isnull和operator之间的区别(!=)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





任何人都可以告诉我isnull功能之间的区别是!=运营商。



我尝试了什么:



例如

我想找到没有经理的员工或者其经理是NULL。

我应该使用ISNULL函数或!=运算符,哪种方法好?为什么?



Hi,

Can anyone please tell me the difference between isnull function is != operator.

What I have tried:

For Example
I want to find employees who do not have manager or whose manager is NULL.
What should i use ISNULL function or != operator and which approach is good? and why?

EmpID	EmpName	ManagerID
1	Gayatri	1
2	Radhika	[NULL]
3	Chetan	[NULL]
4	Ankur	5
5	Chhuts	11

推荐答案

SELECT * FROM MyTable WHERE ISNULL(Manager,0) != 0



如果您想进一步解释,请告诉我。


Let me know if you want further more explanation.


SELECT * FROM MyTable WHERE Manager != NULL

不会给你任何行。

Will give you no rows.

SELECT * FROM MyTable WHERE Manager IS NOT NULL

将为您提供有经理的行。

为什么?因为根据 [] 无法使用比较运算符测试NULL值,例如=,<或<> ;.

NULL通过表达式传播 - 任何涉及NULL值的结果都会导致NULL。所以当你使用一个涉及相等运算符的条件并且其中一个是NULL时,结果不是TRUE或FALSE,它是NULL。

实际上,这两个都会产生相同的结果:

Will give you rows where there is a manager.
Why? Because according to W3Schools[^] "It is not possible to test for NULL values with comparison operators, such as =, <, or <>."
NULLs propagate through expressions - anything involving a NULL value results in NULL. So when you use a condition involving an equality operator and one of the sides is NULL, the result is not TRUE or FALSE, it's NULL.
In fact, both of these will produce the same results:

SELECT * FROM MyTable WHERE Manager != NULL




SELECT * FROM MyTable WHERE Manager = NULL

两者都没有给你行!


这篇关于isnull和operator之间的区别(!=)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:17