Collections:
NULL Values Involved in Comparison Operations in SQL Server
What Happens If NULL Values Are Involved in Comparison Operations in SQL Server Transact-SQL?
✍: FYIcenter.com
If NULL values are involved in comparison operations, the result will be Boolean NULL values. This behavior is very interesting because you would expect a comparison operation returns only one of the two values: TRUE and FALSE. But SQL Server may return you a third value: NULL.
The tutorial script below proves that "1>NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 1>NULL PRINT '1>NULL is returning TRUE' ELSE PRINT '1>NULL is not returning TRUE' GO 1>NULL is not returning TRUE IF NOT 1>NULL PRINT '1>NULL is returning FALSE' ELSE PRINT '1>NULL is not returning FALSE' GO 1>NULL is not returning FALSE
Another test proves that "'FYI'=NULL" is not returning TRUE or FALSE. It is returning a third value, NULL:
IF 'FYI'=NULL PRINT '''FYI''=NULL returns TRUE' ELSE PRINT '''FYI''=NULL does not return TRUE' GO 'FYI'=NULL does not return TRUE IF NOT 'FYI'=NULL PRINT '''FYI''=NULL returns FALSE' ELSE PRINT '''FYI''=NULL does not return FALSE' GO 'FYI'=NULL does not return FALSE
2017-02-03, 798👍, 0💬
Popular Posts:
What Is Open Database Communication (ODBC) in Oracle? ODBC, Open Database Communication, a standard ...
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...
How To Install PHP on Windows in MySQL? The best way to download and install PHP on Windows systems ...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...