In SQL Server, why is NULL not equal to an empty string AND is not equal to an empty string?

This will obviously not return a string ...

select 1 where null = ''

But why does this also not return a string?

select 1 where null <> ''

How can both of these WHERE be “false”?

+3
source share
7 answers

"How can both of these WHERE be" false "?"

This is not true! The answer is also not "true"! Answer: "We do not know."

Remember NULLas a value that you do not know yet.

Would you bet ''?

Would you bet not ''?

, , . , , . NULL SQL.

+5

SQL Server, ANSI SQL; -)

NULL SQL IEEE NaN : NaN != NaN NaN == NaN . IS NULL SQL ( "IsNaN" IEEE FP). ( : IS NULL/"IsNaN" - .)

NULL = x : NULL =/<> x . , NULL UNKNOWN. , NOT(NULL = '') NULL UNKNOWN ( "false" - - . ). SQL ; -)

SQL Server, : "SET ANSI_NULLS OFF" - . / - "" TSQL.

"" ( ):

SET ANSI_NULLS OFF;
select 'eq' where null = '';       -- no output
select 'ne' where null <> '';      -- output: ne
select 'not' where not(null = ''); -- output: not; null = '' -> False, not(False) -> True

ANSI-NULL ( , , ):

SET ANSI_NULLS ON;
select 'eq' where null = '';       -- no output
select 'ne' where null <> '';      -- no output
select 'not' where not(null = ''); -- no output; null = '' -> Unknown, not(Unknown) -> Unknown

.

+3

Null - . , true false , SQL .

+2

SQL , NULL = x false x ( x NULL), SQL Server . , - NULL, x IS NULL x IS NOT NULL.

+1

NULL false (, : NULL)

NULL - , , -.

0

, , :

. a_horse_with_no_name ( ) !

. non = mathmatical terms, NULL - . - - , "" . NULL .

C. Since NULL is unknown, it is not possible to match two NULL values ​​for equality. If you do not know the value of X, and you do not know the value of Y, then you do not know whether they are equal or not.

0
source

All Articles