Results 1 to 2 of 2
  1. #1
    swetha is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    1

    Cocatenation of strings

    I have written a query to concat two strings,



    select concat([first_name] & ', ' & [last_name]) as [Employee Name] from [employee_details]

    THe above query is returning the result correctly only if both first_name & last_name fields are not empty. If the fields are empty, it is dispalyingcomma (,).

    How to avoid that?

    Can anyone please help me out from this issue?

    Thank you

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try this:

    Code:
     
    SELECT TableName.Field1, TableName.Field2, IIf(Trim([Field1]) Is Null,"Empty" + ", " + [Field2] , [Field1]+ ", " + [Field2]) AS JoinedString
    FROM TableName;
    If Field1 is a Null, you will get 'Empty, Field2' in the third field.

    Otherwise, you will get 'Field1, Field2'.

    You might also run into empty strings but try the above first.

    Let me know if that works.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Comparing Two strings issue
    By ganeshvenkatram in forum Access
    Replies: 2
    Last Post: 06-16-2011, 05:27 AM
  2. Syntax problem? Strings
    By axess_nab in forum Forms
    Replies: 5
    Last Post: 06-01-2011, 03:21 PM
  3. connection strings in vb 2008
    By aiken_Bob in forum Programming
    Replies: 0
    Last Post: 03-14-2011, 08:25 PM
  4. Grouping strings
    By Fre in forum Access
    Replies: 16
    Last Post: 04-24-2010, 03:46 PM
  5. Strings limited to 255 characters
    By ocordero in forum Programming
    Replies: 4
    Last Post: 08-09-2006, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums