Microsoft KB Archive/107561

From BetaArchive Wiki

INF: Assignment of Empty Results Set Does Not Set Variable


The information in this article applies to:

  • Microsoft Windows NT Server versions 3.1, 3.5, 3.51, 3.51 SP2, 3.51 SP5, 4.0, 4.0 SP6, 4.0 SP6a, 4.0 SP4
  • Microsoft Windows NT Workstation versions 3.1, 3.5, 3.51, 3.51 SP2, 3.51 SP5, 4.0, 4.0 SP6, 4.0 SP6a, 4.0 SP4
  • Microsoft SQL Server version 4.2x
  • Microsoft SQL Server 2000 (all editions)


If a local variable is set by the results of a SELECT statement which returns no rows, the value currently stored in the local variable will remain unchanged.


An example of this behavior would be the following statement:

   declare @var int
   select @var = 5
   select @var = dbid from sysdatabases where name = "does not exist"
   select @var 

The above query will return 5 as the results of the final SELECT statement. However, if a local variable is set by a query which explicitly returns NULL, the value of the local variable will be set to NULL.

Additional query words: 4.20 Transact-SQL

Keywords : kbother kbOSWinNT310 kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWinNT400sp1 kbOSWinNT400sp2 kbOSWinNT400sp3 kbOSWinNT400sp4 _IK kbOSWinNT400sp6 kbOSWinNT400sp5 kbSQLServ2000
Issue type :
Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT351xsearch kbWinNT350xsearch kbWinNT400xsearch kbWinNTW350 kbWinNTW350xsearch kbWinNTW351xsearch kbWinNTW351 kbWinNTW400sp4 kbWinNTW310 kbWinNTSsearch kbWinNTS400sp6 kbWinNTS400sp4 kbWinNTS400xsearch kbWinNTS400 kbWinNTS351 kbWinNTS350 kbWinNTS310 kbWinNTS351xsearch kbWinNTS350xsearch kbWinNTS310xsearch kbWinNTS351sp2 kbWinNTS351sp5 kbSQLServSearch kbAudDeveloper kbWinNT310xSearch kbWinNTW310Search kbWinNTW351sp5 kbWinNTW400sp6 kbSQLServ2000Search kbWinNTW351SP2 kbWinNTW400SP6a kbSQLServ2000 kbSQLServ420

Last Reviewed: October 27, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.