PRB: Assignment of NULL Value to Local Variable in SQLID: Q63212
|
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:
declare @a int
select @a=100
select @a=b from test where a=52
select @a
select @a=(select b from test where a=52)
In 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.
This question raises the issue of the different ways SQL Server
treats NULL expressions.
To answer the question of why the assignment of a value to a local
variable works differently when the value is NULL, the following
test was performed using the example listed above:
select @a=b from test where a=52
Additional query words: Transact-SQL Windows NT
Keywords : kbother SSrvTrans SSrvServer SSrvWinNT
Version : OS/2:4.2; winnt:4.2x
Platform : OS/2 winnt
Issue type :
Last Reviewed: March 9, 1999