• Jeff Moden (10/19/2013)


    jonysuise (10/19/2013)


    Jeff Moden (10/18/2013)


    jonysuise (10/18/2013)


    Hi asranantha, 😀

    I would use COALESCE AND CASE, because it's SQL standard.

    I would use just ISNULL AND NULLIF (like Sean did) because you don't have unexpected datatype precedence problems with ISNULL like you can with COALESCE, is a tiny bit faster than COALESCE, takes fewer characters to type, and it ticks all sorts of people off that still think SQL is portable across engines. 😀

    Thanks Jeff. It's a matter of opinion i think. 😀

    Actually, if you make a nice little million row table, you can prove to yourself the slight performance gain. You can also prove to yourself that, if you don't mind you're P's and Q's, the data precedence thing can really mess up performance. 😉

    Check this post :

    http://sqlmag.com/t-sql/coalesce-vs-isnull

    As i said, it's a matter of opinion. I don't think it's correct to point a solution as better than the other one.. just be aware of the pros and cons of each one of them and choose the one that fit your needs. 🙂

    Jonathan Bernardez Bernardez
    ___________________________________________________________
    DBD. MCSA SQL Server 2012