+ -
当前位置:首页 → 问答吧 → NULL不是数值

NULL不是数值

时间:2011-12-28

来源:互联网

SQL code

declare @alive bit;
set @alive = null;

if @alive = 1 or @alive != 1
    print 'Alive or Dead';
else
    print 'Huh? Neither alive nor dead';
    
if @alive=@alive
    PRINT 'It must equal itself, right?'
ELSE
    PRINT 'Not always. null does not equal null';
    



Huh? Neither alive nor dead
Not always. null does not equal null

代码挺有意思的。

作者: houyajin   发布时间: 2011-12-28

yes, null does not equal null!

作者: qianjin036a   发布时间: 2011-12-28

SQL code
declare @alive bit;
set @alive = null;

if @alive = 1 or @alive != 1
    print 'Alive or Dead';
else
    print 'Huh? Neither alive nor dead';
    
if null is null
    PRINT 'It must equal itself, right?'
ELSE
    PRINT 'Not always. null does not equal null';
/*
Huh? Neither alive nor dead
It must equal itself, right?
    
    

作者: Monkey__D__Luffy   发布时间: 2011-12-28

Null is woman's looks

作者: qianjin036a   发布时间: 2011-12-28

null does not equal null

作者: Beirut   发布时间: 2011-12-28

SQL code
What would be the output ?

declare @a smallint 
set @a = 0 
select nullif ( @a , '' )


这个更有意思

作者: Beirut   发布时间: 2011-12-28

NULL<>''

作者: fredrickhu   发布时间: 2011-12-28


mark

作者: ju523756055   发布时间: 2011-12-28

null does not equal null!
null is null!

作者: maco_wang   发布时间: 2011-12-28

俺只会中文
NULL确实不能比较只能IS

作者: futulove   发布时间: 2011-12-28

改了配置已经可以比较哦

作者: kuqideyupian   发布时间: 2011-12-28

+1
引用 9 楼 futulove 的回复:
俺只会中文
NULL确实不能比较只能IS

作者: q465897859   发布时间: 2011-12-28

都是些外国人。呵呵 null是什么都没有的意思。所以由此所得 null就不是数字

作者: szstephenzhou   发布时间: 2011-12-28

is null

作者: rings2000   发布时间: 2011-12-28

其实楼主是拉晒英文呢

作者: Beirut   发布时间: 2011-12-28

null=undefined value=未知

作者: roy_88   发布时间: 2011-12-28

set ansi_nulls off后结果就不同了.
SQL code

set ansi_nulls off
declare @alive bit;
set @alive = null;

if @alive = 1 or @alive != 1
    print 'Alive or Dead';
else
    print 'Huh? Neither alive nor dead';
    
if @alive=@alive
    PRINT 'It must equal itself, right?'
ELSE
    PRINT 'Not always. null does not equal null';

--> 结果
Alive or Dead
It must equal itself, right?

作者: ap0405140   发布时间: 2011-12-28

null确实不能比较 但是可以通过 isnull转化在比较 isnull(字段,'') 如果是NULL则转化为 ‘’ 空字符串

作者: feng1366259807   发布时间: 2011-12-28

引用 5 楼 beirut 的回复:

SQL code
What would be the output ?

declare @a smallint
set @a = 0
select nullif ( @a , '' )


这个更有意思


见识了。

作者: houyajin   发布时间: 2011-12-28

引用 14 楼 beirut 的回复:

其实楼主是拉晒英文呢


挂这么多牌牌,还欺负人么?
偶要是英文好,就不写一个汉字。

作者: houyajin   发布时间: 2011-12-28

引用 16 楼 ap0405140 的回复:

set ansi_nulls off后结果就不同了.
SQL code

set ansi_nulls off
declare @alive bit;
set @alive = null;

if @alive = 1 or @alive != 1
print 'Alive or Dead';
else
print 'Huh? Neither alive nor dead';……


这个好玩。下班!!

作者: houyajin   发布时间: 2011-12-28

引用 19 楼 houyajin 的回复:

引用 14 楼 beirut 的回复:

其实楼主是拉晒英文呢


挂这么多牌牌,还欺负人么?
偶要是英文好,就不写一个汉字。

 哪有欺负你的味道我怎么看不出来。

作者: Beirut   发布时间: 2011-12-28

引用 18 楼 houyajin 的回复:

引用 5 楼 beirut 的回复:

SQL code
What would be the output ?

declare @a smallint
set @a = 0
select nullif ( @a , '' )


这个更有意思


见识了。

能引起注意 不容易啊,哥的回答向来不被别人重视

作者: Beirut   发布时间: 2011-12-28