0

Reading the MSDN article about T-SQL CREATE PROCEDURE statement, I've come across a sentence that I just can not understand.

In the "Best Practices" section, they say:

Use modification statements that convert nulls and include logic that eliminates rows with null values from queries. Be aware that in Transact-SQL, NULL is not an empty or “nothing” value. It is a placeholder for an unknown value and can cause unexpected behavior, especially when querying for result sets or using AGGREGATE functions.

Can anybody explain me, what do they mean? I am confused, because I always thought that NULL means empty value, or missing value, or just "nothing".

Update: I've just found a similar question. They spot that in comparison, NULL != NULL. So NULL values can never be equal to anything. That's good point. Is there anything else?

Community
  • 1
  • 1
C-F
  • 1,597
  • 16
  • 25
  • You can also use ISNULL(colName, 0) where 0 will be null's replacement value. Which means you can compare values that are both null. – Frank Apr 11 '14 at 00:44
  • 1
    I believe it's just trying to emphasize that it's not a `0` in an `int` column, say, and it's not the zero-length string in a `varchar` column, etc. – Damien_The_Unbeliever Apr 11 '14 at 06:42

1 Answers1

0

The NULL value means: "the value is not set". This is why they call it as a placeholder. Two not set values can not be equal.

You have to handle the NULL 'values' if it is required by the business process, or the expected result requires it.

Check this article to learn more about NULL: http://technet.microsoft.com/en-us/library/ms191504(v=sql.105).aspx

Pred
  • 8,789
  • 3
  • 26
  • 46