INF: Assignment of Empty Results Set Does Not Set Variable (107561)



The information in this article applies to:

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

This article was previously published under Q107561

SUMMARY

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.

MORE INFORMATION

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.

Modification Type:MinorLast Reviewed:2/22/2005
Keywords:kbother KB107561