But Why? If one or both parts of a comparison is null, the result of the comparison will be UNKNOWN, which is treated like false in a case structure.
The issue is that NULL is not considered to be equal to anything even not to itself, but the strange part is that is also not not equal to itself. In comparison, in general programming languages null is treated is a regular value and is equal to itself, however the is the NAN value which is also not equal to itself, but at least it returns 'false' when comparing it to itself, and when checking for not equals different programming languages have different implementations.
Note however that in the Basic languages i. VB etc. NULL does not equal anything. There are also several system stored procedures that are written incorrectly with your syntax.
Wish I knew how to notify Microsoft of those mistakes as I'm not able to change the system stored procs. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 6 months ago. Active 7 months ago. Viewed k times. Improve this question. Add a comment. Active Oldest Votes. Improve this answer. Kirk Woll Marcelo Cantos Marcelo Cantos k 37 37 gold badges silver badges bronze badges. It's marginally less efficient, but much more elegant. The index seek operator details show us there is not any difference between the Actual Number of Rows and the Estimated Number of Rows.
This situation shows that the query optimizer finds accurate information about how many NULL rows are stored in the MiddleName column. Most likely, the following question will pop up in your mind. Basically, the statistics store the data distribution about the tables, and the query optimizer makes use of this information during the creation of a query plan. When we create an index this data distribution information is also stored for the NULL valued columns.
So that, optimizer estimates how much memory and other resources are required for a query. As we can see there is an number of NULL values are stored in the MiddleName column and this information is used by the query optimizer. In some cases, the ISNULL function is used with the where condition but this usage method may lead to use indexes inefficiently.
However, this query cannot use the created non-clustered index so it will read all index pages and then return the appropriate rows.
To eliminate this situation, we can make a little code modification in the query so that the query optimizer can use the indexes more efficiently. The following query returns some rows as like the previous one but it uses the indexes more efficiently. FROM Person. Null values cannot be used as information that is required to distinguish one row in a table from another row in a table, such as primary keys, or for information used to distribute rows, such as distribution keys.
This need for three-valued logic is a source of many application errors. These tables provide examples of this behavior. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info.
0コメント