SQL Server - row selection does not return any NULL values. What for?

I have the following SQL table:

CREATE TABLE [dbo].[Test](
    [TestID] [int] NOT NULL,
    [TestNum] [int] NULL,
    [TestReason] [varchar](50) NULL
)

So TestNum INT , which allows you to use NULL values, and I put a large amount of data into the table, of which some rows contain a NULL value for TestNum

If I then run the following query

select *
from Test
where TestNum != 123

The aboe query does not return null strings . I expect it to return ALL rows, EXCLUDING those that have a value of 123.

Why is this?

I run this query in MS-SQL 2000 DB imported into MS SQL 2005. Does this have any effect? Or is this standard behavior for all versions of MS SQL Server?

+3
2

NULL "". NULL = NULL . NULL, "OR TestNum IS NULL".

+12

Try

SELECT * FROM Test WHERE TestNum != 123 OR TestNum IS NULL

NULL , . NULL 123 ; .

+1

Source: https://habr.com/ru/post/1752843/


All Articles