Results 1 to 3 of 3

Thread: if statement

  1. #1
    Join Date
    Oct 2002
    Posts
    9

    Question Unanswered: if statement

    I am trying to build a query that will dynamically change my output if a field is null.

    For example this is my table:

    First Name Last Name Full Name
    Richie Rich Richie Rich
    NULL NULL Lisa Jones
    John Smith NULL

    I need my output to be:

    Richie Rich
    Lisa Jones
    John Smith

    Is it possible to select only the First and Last Name when both fields are not null (then concatenate) and select only Full Name when one of the other fields are null?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    piece of case, er, cake...

    select
    case
    when firstname is null
    then fullname
    when lastname is null
    then fullname
    else firstname||' '||lastname
    end as nameselected
    from yourtable

    rudy
    http://rudy.ca/

  3. #3
    Join Date
    Oct 2002
    Posts
    9

    Thumbs up Thanks

    Works perfect!!!

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •