Results 1 to 2 of 2

Thread: Merging fields in a query??

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Merging fields in a query??

    Hi All,
    I am having difficulty with a query

    Basically I want to Merge three fields into one field in a query from my table as they are three lines of an address.

    I used the following code in query design:
    [Address Line 1]&" "&[Address Line 2]&" "&[Address Line 3]
    Which worked perfectly, however I need these seperated with a comma so I adjusted as follows:
    [Address Line 1]&", "&[Address Line 2]&", "&[Address Line 3]

    Which again worked HOWEVER my problem is that half of the entries do not have an Address Line 2 so there output in the query is; address line 1, , address line 3.
    How do I get rid of the second comma if the second field (address line 2) is blank???

    Thanking you in advance

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    CONCAT(address1, ', ', IF(address2 != '', CONCAT(address2, ', ', '')), address3)
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    boogyman (01-30-2009)

Bookmarks

Posting Permissions

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