using SQL case statements HOW???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lisa

    using SQL case statements HOW???

    I'm trying to make a view that uses organization name from one table
    and contact first and last name from another table. In the view I
    have a field that I want to show Organization followed by the main
    contact. Problem is if the organization field or name field is NULL
    then it doesn't show anything. If one field is empty I still want it
    to show the other field in the table.
    Example:
    Org1--Contact
    Org2--Contact
    Org3 (Still shows org even without a contact name)
    Contact (Still shows contact even without an org name)

    Tried using a CASE statement but didn't work.
  • Shervin Shapourian

    #2
    Re: using SQL case statements HOW???

    Lisa,

    You don't need a CASE to do that. Just put your fields in COALESCE, like
    this:

    select COALESCE(Organi zation, '') + COALESCE(' -- ' + Contact, '')
    from YourTables

    Shervin

    "Lisa" <lisauofi@yahoo .com> wrote in message
    news:efcee87b.0 310161331.8865c a9@posting.goog le.com...[color=blue]
    > I'm trying to make a view that uses organization name from one table
    > and contact first and last name from another table. In the view I
    > have a field that I want to show Organization followed by the main
    > contact. Problem is if the organization field or name field is NULL
    > then it doesn't show anything. If one field is empty I still want it
    > to show the other field in the table.
    > Example:
    > Org1--Contact
    > Org2--Contact
    > Org3 (Still shows org even without a contact name)
    > Contact (Still shows contact even without an org name)
    >
    > Tried using a CASE statement but didn't work.[/color]


    Comment

    Working...