在sql server中使用空(NULL)int数据类型

时间:2022-12-16 10:24:35

How to select an int datatype field(bonus) which is inserted as NULL?

如何选择插入为NULL的int数据类型字段(奖金)?

Tried the following but prints nothing though there is a valid entry.

试过以下但是虽然有一个有效的条目但没有打印。

select e_name from employee, payroll where datepart(year,hire_date)=2005 and employee.e#=payroll.e# and bonus=null

also if i want to add another year say 2007 to be checked with 2005 using or, what is the query for that?

另外如果我想添加另一年说2007年要用2005检查,或者是什么查询?

1 个解决方案

#1


3  

When testing for null, you must use this syntax:

测试null时,必须使用以下语法:

... 
and bonus is null

FYI the syntax for testing if not null is bonus is not null.

FYI测试语法如果不为null则奖励不为空。

All other comparisons (eg =, <, like, etc) will return false with a null value.

所有其他比较(例如=,<,like等)将返回false并返回null值。

#1


3  

When testing for null, you must use this syntax:

测试null时,必须使用以下语法:

... 
and bonus is null

FYI the syntax for testing if not null is bonus is not null.

FYI测试语法如果不为null则奖励不为空。

All other comparisons (eg =, <, like, etc) will return false with a null value.

所有其他比较(例如=,<,like等)将返回false并返回null值。