• bambang (12/11/2009)


    Just wondering,

    I like to use ISNULL(column_name, 0) while my friend like to use COALESCE(column_name, 0).

    We both try using ISNULL and COALESCE in our query and there is no different result.

    In Books online, it's said that both behave differently. There's also the explanation, but I just don't

    understand it completely :p

    Is there any article regarding this topic?

    And which one you usually use (ISNULL or COALESCE) and why you use it?

    For now, I'll keep my habit using ISNULL, so will my friend keep using COALESCE 😀

    Thanx for any explanation, link, or you opinion 🙂

    1. ISNULL is actually a tiny bit faster than COALESCE but it takes millions of rows to notice.

    2. ISNULL is shorter to type than COALESCE.

    3. ISNULL converts the second operand to the same datatype as the first. COALESCE selects the datatype of the operand that has the highest data precidence. THAT can make for some real performance problems if you're not careful.

    4. If you believe in the myth of truly portable code (and I don't except maybe for basic "CRUD"), COALESCE is ANSI where ISNULL is not.

    I agree that it's nearly a personal choice and my personal choice is to use ISNULL where ever I can.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)