Help with COALESCE logic - is it the same as this query?

  • I think this works, but just want to make sure....I have the following query snippet:

    AND

    (

    (CodeType = 'Task Type' AND AccountID = 1)

    OR

    (CodeType IS NULL AND AccountID IS NULL)

    )

    Could this be accomplished by this:

    AND COALESCE(CodeType , 'Task Type') = 'Task Type'

    AND COALESCE(AccountID , 1) = 1

    Do I gain anything by getting rid of the 'OR'? Is one more clean than the other?

  • In my understanding, they are functionally the same. The benefit I see is that it's easier to read using COALESCE.

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Jason Selburg (2/15/2008)


    In my understanding, they are functionally the same. The benefit I see is that it's easier to read using COALESCE.

    Thanks, that was my thinking, too regarding the 'easier to read'. Thanks again!

Viewing 3 posts - 1 through 2 (of 2 total)

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