The information in this article applies to:
SYMPTOMS
Suppose a table named "test" has columns named "a" and "b", where
the highest value of "a" is 2. "@a" is assigned a value in the
normal way, as follows:
It is expected that this query will return NULL because "a" is never 52. However, the query returns 100, which is the number that was first assigned to it. If the third line of the above query is replaced with the following line, NULL is returned as expected:
CAUSEIn the example listed above, the SELECT statement returns zero rows. Because there is no value of "b" returned from the query, SQL Server treats the previous value of @a (100) as the "default value" to use. This is the reason it does not return NULL as expected. WORKAROUND
This question raises the issue of the different ways SQL Server
treats NULL expressions.
The difference between this test and the test listed above is the "value" of "b" returned from the query. The second SELECT statement is needed so that the return value of the "entire expression" can be obtained, which is NULL, rather than the return value of "b". Additional query words: Transact-SQL Windows NT
Keywords : kbother SSrvTrans SSrvServer SSrvWinNT |
Last Reviewed: March 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |