FIX: Error 515 with Concatenated NULLs in WHERE Clause and ORDER BY

This article was previously published under Q248442
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 56173 (SQLBUG_70)
A query may return error 515, which is the following:
Cannot insert the value NULL into column '', table ''; column does not allow nulls. INSERT fails.
This can occur if all of the following conditions are true:
  • A string concatenation is done in the WHERE clause against a character column.
  • This column is used in an ORDER BY clause.
  • This column contains a NULL.
  • This column is not indexed.
  • The concat_null_yields_null option is not set for this connection or this database. This condition can be met by any one of the following:

    • Explicitly issuing the command set concat_null_yields_null off.
    • Using a client application that uses DB-Library or an ODBC driver older than version 3.70.0623.
    • Running the database in SQL Server 6.x compatibility mode.
To work around this problem, eliminate one of the preceding conditions that are known to cause it. For example, create an index on the column, or eliminate the NULL value(s).

Usually, the best work around is to index the column used in the ORDER BY clause. In addition to resolving this problem, in most cases, a query gains performance from indexing the columns used with the ORDER BY clause.
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.

Article ID: 248442 - Last Review: 12/05/2015 17:54:09 - Revision: 2.1

Microsoft SQL Server 7.0 Standard Edition

  • kbnosurvey kbarchive kbbug kbfix KB248442