• PChiragS

    SSCarpal Tunnel

    Points: 4965

    Nice question..Thanks.


    SSC Guru

    Points: 281243

    Andrew Watson-478275 (9/20/2013)

    As well as the reference given, this one should be included too:


    Jason...AKA CirqueDeSQLeil
    I have given a name to my pain...MCM SQL Server, MVP
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • NBSteve

    Hall of Fame

    Points: 3427

    Good question, but it does miss out on a good opportunity to point out that these two have the same result (in this particular case):

    SELECT COALESCE(Col1, Col2) AS 'FirstNotNull' FROM dbo.T_TEST

    SELECT ISNULL(Col1, Col2) AS 'FirstNotNull' FROM dbo.T_TEST

    while these two do not:

    SELECT COALESCE(Col2, Col1) AS 'FirstNotNull' FROM dbo.T_TEST

    SELECT ISNULL(Col2, Col1) AS 'FirstNotNull' FROM dbo.T_TEST

    (The reason being that COALESCE uses data type precedence rules, converting results to DECIMAL, while ISNULL uses the data type of the first argument, assuming it's not a literal NULL, converting everything to INT in the latter example.)

  • Revenant


    Points: 42467

    Nice and easy - thanks!

  • jfgoude


    Points: 2586

    Elementary, my dear Watson



Viewing 5 posts - 16 through 20 (of 20 total)

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