REPLACE behavior

  • Comments posted to this topic are about the item REPLACE behavior

  • Easy one, thanks.

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • Too easy, no need even to run the code this time πŸ™‚

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • nice question .. thanks for sharing

  • Interesting caveat, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Nice one thanks.

    Hope this helps...

    Ford Fairlane
    Rock and Roll Detective

  • Good question!

    In Oracle, the answer is 'ABC'.

    Just shows that when you think you know something... sometimes you don't!

  • This was removed by the editor as SPAM

  • Easy - so why only 68% with correct answers?

  • In many programming languages the third argument wouldn't even be evalutated if the second argument didn't appear in the first argument.

    All these will just return 'ABC':

    SELECT REPLACE('ABC', 'Z', 1)

    SELECT REPLACE('ABC', 'Z', CURRENT_TIMESTAMP)

    SELECT REPLACE('ABC', 'Z', '#$@%')

    This one will return 'ABC' half of the time and NULL the other half.

    SELECT REPLACE('ABC', 'Z', CASE WHEN RAND() < 0.5 THEN 'A' END)

    I thought of making the problem more complex, but I figured that would result in more people just running the query instead of answering first! πŸ˜‰

  • paul s-306273 (3/6/2014)


    Easy - so why only 68% with correct answers?

    Perhaps it wasn't as easy as some of the resident "experts" claim. It's anything but logical behaviour and you can only get the question correct if you know that caveat on the REPLACE function (or if you just run the code).

  • Thanks, easy one, it's even documented in BOL. πŸ™‚

    /HΓ₯kan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

  • Koen Verbeeck (3/6/2014)


    Interesting caveat, thanks.

    +1

  • Richard Warr (3/6/2014)


    It's anything but logical behaviour and you can only get the question correct if you know that caveat on the REPLACE function (or if you just run the code).

    Developer A: "We have a bug in this function. Want me to fix it?"

    Developer B: "Nah, just document it as normal behavior."

    Developer A: "Done."

    -----
    a haiku...

    NULL is not zero
    NULL is not an empty string
    NULL is the unknown

Viewing 15 posts - 1 through 15 (of 25 total)

You must be logged in to reply to this topic. Login to reply