Isnull erroneous return?

I have the following query:

SELECT apps.Field4,
       ISNULL(apps.field4, '-1')
FROM   applications apps
WHERE  apps.OBJECT_ID = 1727847
       AND ISNULL(apps.Field4, -1) = -1 

apps.field4is an integer, and no record has a value less than 0 for field4.

Return values ​​for the above query:

+------+----+
| NULL | -1 |
+------+----+

But if I add AND apps.field4 is NULLa where clause, the entries are not returned:

SELECT apps.Field4,
       ISNULL(apps.field4, '-1')
FROM   applications apps
WHERE  apps.OBJECT_ID = 1727847
       AND apps.field4 IS NULL
       AND ISNULL(apps.Field4, -1) = -1 

Why ISNULLdoes it seem to correctly identify the value NULL, but IS NULLdoes not work?

+4
source share
2 answers

I know that I am not answering your question. However, I found something interesting on MSDN:

. NULL WHERE ISNULL, NULL. IS NULL. NULL . IS NULL.

USE AdventureWorks2012;
GO
SELECT Name, Weight
FROM Production.Product
WHERE Weight IS NULL;
GO

https://msdn.microsoft.com/en-us/library/ms184325.aspx

0

, . DBCC CHECKDB DBCC CHECKTABLE, , .

0

All Articles