Trouble with decode

  • Hi,

    Can somebody help me how to convert this to sql server query using CASE stmt?

    ,DECODE(c1.name, NULL, NULL, DECODE(c1.first_name, NULL, c1.name, c1.name || ', ' || c1.first_name))

  • Something like this?

    CASE WHEN c1.name IS NULL THEN NULL

    ELSE CASE WHEN c1.first_name IS NULL THEN c1.name

    ELSE c1.name + ', ' + c1.first_name END

    END

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Thank u so much Mark!!

    one doubt..Will CASE work the same as DECODE in case of nulls or should we add like

    CASE WHEN c1.name IS NULL THEN NULL

    ELSE CASE WHEN c1.first_name IS NULL THEN c1.name

    ELSE isnull(c1.name,'') + ', ' + isnull(c1.first_name,'') END

    END

  • rekha_sara (8/31/2009)


    Thank u so much Mark!!

    one doubt..Will CASE work the same as DECODE in case of nulls or should we add like

    CASE WHEN c1.name IS NULL THEN NULL

    ELSE CASE WHEN c1.first_name IS NULL THEN c1.name

    ELSE isnull(c1.name,'') + ', ' + isnull(c1.first_name,'') END

    END

    You won't need the ISNULLs (although they are not harmful), you will only get to that part of the CASE expression if both c1.name and c1.first_name are non-NULL.

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • hello friends....Thnaks for the information.....

    Buy Teeth Whitening [/url]

Viewing 5 posts - 1 through 4 (of 4 total)

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