• SQL uses Three-Valued Logic; it is not tied to the Two-Valued Logic you have forced on it in this article.  Your comparison of @val = NULL does not result in FALSE.  It results in UNKNOWN.  You are being misled by the fact that you are printing 'FALSE' to the screen after the initial comparison.  This is how IF works in SQL:

    IF (a = b)

         PRINT 'TRUE'

    ELSE

         PRINT 'FALSE'

    In the example, if a equals b is True, then 'TRUE' is printed on the screen; otherwise, 'FALSE' is printed on the screen.  For two-valued logic (i.e., C++, VB, etc. logic) the result can be only True or False; so using ELSE as a catch-all for anything other than True does not present a problem.  However, in three-valued logic this presents a problem which can be demonstrated here:

    IF (a = b)

         PRINT 'TRUE'

    ELSE IF NOT(a = b)

         PRINT 'FALSE'

    ELSE

         PRINT 'UNKNOWN'

    In this case, if a or b is NULL, the result of comparison is neither True nor False; it is Unknown.  The example above will print UNKNOWN if a = b results in Unknown.  Three-valued logic requires three comparisons to determine the exact result of the expression as you can see from the above.