Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Unanswered: Nesting IIF in SQL

    Hello, I need some help with nesting an IIF.

    Lets say I have a table like this,

    Gender, initials, name, address, postalcode, town

    male, J., Ivens, Javalaan 3, B1015, Bruxelles
    female, K., Kwakman, Boumablv. 4, 9600 AA, Groningen
    unknown , A., Robben, Brink 200, 9411 BB, Bedum


    I want to join some of this data in new columns, I came up with this,

    SELECT IIF(gender='female', 'Ms.','Mr.') & (' ' & initials & ' ' & name) AS column1,
    (address) AS column2,
    (postalcode &' ' & town) AS column3
    FROM Sheet1;


    With this result,

    column1, column2, column3
    Mr. J. Ivens , Javalaan 3, 1015 Bruxelles Belgium
    Ms. K. Kwakman, Boumablv. 4, 9600 AA Groningen
    Mr. A. Robben, Brink 200, 9411 BB Bedum

    Now for that last record the gender is unknown. I want it to read "Mr./Ms. A. Robben" instead of "Mr. A. Robben".

    How do I do this? I thought of nesting that IIF but I can't figure it out.

    Thanks in advance

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT IIF( gender='male' , 'Mr.'
              , IIF( gender='female' , 'Ms'
                       , 'Mr./Ms') ) 
                & ' ' & initials & ' ' & name AS column1
         , address AS column2
         , postalcode & ' ' & town AS column3
      FROM Sheet1;
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2012
    Posts
    4
    That works, thanks. These are my first steps from dBase to Access. Quick help like this will make things easier

Posting Permissions

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