Results 1 to 4 of 4
  1. #1
    bryan0 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Connecticut
    Posts
    19

    Concatenate Results of Query

    Hello, I have a simple query that returns a column of items, but i would like to concatenate them all into a single string if possible.

    For example, this query:
    Code:
    SELECT CITY FROM CITY_STATE WHERE STATE = 'California';
    Would return:
    Sacramento
    Oakland
    Los Angeles
    San Diego

    However, I want a comma separated string like "Sacramento, Oakland, Los Angeles, San Diego".



    I did a lot of searching and found solutions using COALESCE, but that function is not supported in MS Access. Any ideas would be appreciated!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    see this

    But why this format. Suppose there are 4000 cities in California??

  3. #3
    LeightonStew is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    2
    Quote Originally Posted by bryan0 View Post
    Hello, I have a simple query that returns a column of items, but i would like to concatenate them all into a single string if possible.

    For example, this query:
    Code:
    SELECT CITY FROM CITY_STATE WHERE STATE = 'California';
    Would return:
    Sacramento
    Oakland
    Los Angeles
    San Diego

    However, I want a comma separated string like "Sacramento, Oakland, Los Angeles, San Diego".

    I did a lot of searching and found solutions using COALESCE, but that function is not supported in MS Access. Any ideas would be appreciated!
    ====================
    As a Macro, maybe something haywire such as creating a cross tab query, exporting the results as CSV, reading them back in.

    Otherwise I have used VBA to write a custom function. For example:http://allenbrowne.com/func-concat.html

  4. #4
    LeightonStew is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    2
    Stack Overflow has a related post... and a pretty elegant ADO approach:
    http://stackoverflow.com/questions/1...ield-in-access

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

Similar Threads

  1. Query to concatenate records - newb
    By bentod in forum Queries
    Replies: 7
    Last Post: 10-08-2012, 12:06 PM
  2. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  3. Concatenate records in Query
    By cleon in forum Queries
    Replies: 3
    Last Post: 04-08-2012, 11:14 AM
  4. Using a query to concatenate data
    By ocampod in forum Queries
    Replies: 15
    Last Post: 03-20-2012, 08:11 AM
  5. Concatenate Query Results
    By Rawb in forum Queries
    Replies: 6
    Last Post: 01-19-2011, 07:50 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