where条件为null(coloumn name,0) - ? [英] Where condition is null(coloumn name, 0) - ?

查看:120
本文介绍了where条件为null(coloumn name,0) - ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 选择 * 来自 tbl_name 
其中 ISNULL(ID, 0 )= xxx





在上面的陈述中,



如果xxx = 0那么什么是ISNULL(ID,0)

如果xxx = 1然后是什么是ISNULL(ID,0)

如果xxx = 122那么什么是ISNULL(ID,0)



如何ISNULL(ID,0)在where条件

解决方案

 isnull中取代 NULL   指定的替换值。



 ISNULL(ID, x)替换全部  null   ID   x 
其中 x =有值。

< br $> b $ b

< pre lang =SQL> 其中 Id = 0(没有isnull 检查)表示 ll跳过表中包含空值的所有ID。
并且存在另一个问题,即某些数据类型与null值不可比,因此在这种情况下,您可以获得比较错误。
所以,使用isnull(ID,0)用于将ID的所有空值设置为0,然后复制到条件值(xxx)。





了解更多信息请查看..

http://msdn.microsoft.com/en-us/library/ms184325.aspx [ ^ ]


如果ID列为null,则ISNULL(ID,0)将返回零,否则它返回ID列值,所以:

 如果 xxx =  0    -   给你0  
if xxx = 1 - 给你1
如果 xxx = 122 - 给你122


select * from tbl_name
where ISNULL(ID,0) = xxx



Here in above statement ,

if xxx = 0 then what is ISNULL(ID,0)
if xxx = 1 then what is ISNULL(ID,0)
if xxx = 122 then what is ISNULL(ID,0)

how does ISNULL(ID,0) works in where condition

解决方案

isnull Replaces NULL with the specified replacement value.


ISNULL(ID,x) replaces all the null value of ID with x
where x= has a value.



where Id=0(without isnull check) means it'll skip all the ID containing the null value in the table.
and there is another problem that there are some datatype that are not comparable with the null value so in that case you can get the comparison error.
so, using isnull(ID,0) is used to set all the null value of ID by 0 and then coparing to the condition value(xxx).



for more info check this..
http://msdn.microsoft.com/en-us/library/ms184325.aspx[^]


ISNULL(ID,0) will return zero if the ID column is null, otherwise it returns ID column value, So:

if xxx = 0  -- give you 0
if xxx = 1  -- give you 1
if xxx = 122 -- give you 122


这篇关于where条件为null(coloumn name,0) - ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆