PRB: REPLACE Sets First String to NULL if Third String is NULL (271601)



The information in this article applies to:

  • Microsoft SQL Server 7.0
  • Microsoft SQL Server 2000 (all editions)

This article was previously published under Q271601

SYMPTOMS

The following query returns NULL although you might expect the query to return the first string, '3', because the second string, 'X', is not contained within the first string.
SELECT REPLACE('3', 'X', NULL)
				

CAUSE

Regardless of whether or not the second string is contained in the first string, if you pass NULL as any argument to the REPLACE function, it returns NULL. One of the first things that the REPLACE function does is to make sure that it is possible to perform the replace. Because replacing a portion of a string with an unknown value results in an unknown value, it is not possible.

MORE INFORMATION

Future versions of Microsoft SQL Server Books Online will include this information.

Modification Type:MajorLast Reviewed:10/17/2003
Keywords:kbprb KB271601