• webrunner (7/12/2010)


    I guess my question is why does the REPLACE function replace anything if the string pattern (second parameter) isn't in the string expression (first parameter)?

    It doesn't. It checks for NULL before doing any replacing. This is because of the special quality of NULL. As posted before, unknown in -> unknown out.

    The problem comes because we are used to thinking of replace as two operations:

    1. Look for a search string within the given string.

    2. If found, replace with replacement string.

    The conditional there allows us to ignore an unknown or invalid third parameter if there's no replacement to be made.

    But that's procedural thinking. Declarative thinking would phrase it more like* "The given string with replacement string in place of all instances of search string".

    There's no conditional, so all inputs have to be considered in the function. Consequently, since one of the inputs is unknown, the result should be unknown as well.

    * or some such; I'm certainly not an expert on declarative syntax.