Results 1 to 11 of 11
  1. #1
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43

    Concatenating related fields

    I have data like this:

    Table ExistingBinData:
    VariantName|Bin
    XYZ|QTY. 5 @ SHELF 3
    XYZ|QTY. 1 @ SHELF 2
    XYZ|QTY. 1 @ SHELF 17
    ABC|QTY. 3 @ SHELF 13
    ABC|QTY. 2 @ SHELF 12

    I used Allen Browne's Concat Related function found here: http://allenbrowne.com/func-concat.html to get the below result:

    Code:
    SELECT ExistingBinData.VariantName, ConcatRelated("Bin","ExistingBinData","[VariantName] = """ & [VariantName] & """") AS Bins
    FROM ExistingBinData
    ORDER BY ExistingBinData.VariantName;

    Query ExistingBinsUngrouped:
    VariantName|Bins
    XYZ|QTY. 5 @ SHELF 3, QTY. 5 @ SHELF 3, QTY. 1 @ SHELF 17
    XYZ|QTY. 5 @ SHELF 3, QTY. 5 @ SHELF 3, QTY. 1 @ SHELF 17
    XYZ|QTY. 5 @ SHELF 3, QTY. 5 @ SHELF 3, QTY. 1 @ SHELF 17
    ABC|QTY. 3 @ SHELF 13, QTY. 2 @ SHELF 12
    ABC|QTY. 3 @ SHELF 13, QTY. 2 @ SHELF 12

    The above query takes just a couple seconds to run. My problem is that I need to Group By VariantName but the moment I do so, whether adding Group By within the query above, or by creating another query to query the query above and using Group By there and either way makes the query take about 15 minutes to run to Group 15k records down to 10k. Any Ideas on how to speed it up?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    =field1 & field2

  3. #3
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43
    Sorry, but can you elaborate on that at all? Just to be clear, I am not concatenating fields, I am concatenating records into one string.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    what you posted looks grouped (XYZ, ABC). If you simply didn't show how it's not grouped, then maybe what you simply need is to sort on VariantName.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43
    If it was grouped on VariantName, wouldn't ABC, XYZ not be repeated? What I have posted above is not grouped.

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    No, it would still repeat if we're talking about a query. Otherwise, what would you expect to see in that field on the 2nd and 3rd records?
    What I have posted above is not grouped.
    Maybe it's not specifically grouped using the Group clause in a query, but the way you show it is represented as such. Thus it either has to be grouped, or it's sorted, or it's just coincidence that it looks like it could be either.

  7. #7
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43
    Well if I add "GROUP BY ExistingBinData.VariantName"

    Code:
    SELECT ExistingBinData.VariantName, ConcatRelated("Bin","ExistingBinData","[VariantName] = """ & [VariantName] & """") AS Bins
    FROM ExistingBinDataa
    GROUP BY ExistingBinData.VariantName
    ORDER BY ExistingBinData.VariantName;
    I get the below, without repeating rows for VariantName , which is the desired outcome, it just takes a very long time, which is the reason for my post.

    XYZ|QTY. 5 @ SHELF 3, QTY. 5 @ SHELF 3, QTY. 1 @ SHELF 17
    ABC|QTY. 3 @ SHELF 13, QTY. 2 @ SHELF 12

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Sorry, with all that concatenation I missed that each record for a VariantName was exactly the same. Did you try the DISTINCT (or DISTINCT ROW) predicate and see how long that takes? I would suspect less time than GROUP BY, but don't know by what factor.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Whether DISTINCT or GROUP BY, functions like ConcatRelated can cause slow performance in queries with large datasets. Possibly only way to speed up is to save the un-grouped recordset to a 'temp' table (table is permanent, records are temporary) then run GROUP BY or DISTINCT on that table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43
    Thanks for the suggestion, I tried DISTINCT ROW ....didn't change the outcome at all, still had repeated rows, DISTINCT works, but takes even longer than the Group By option.

  11. #11
    btappan is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2013
    Posts
    43
    I wound up turning the ungrouped query into a make table query, and then ran a grouped query on the make table instead. That dropped the execution time down from 15 minutes, to around 1 minute. Thanks for the suggestions guys.

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

Similar Threads

  1. Replies: 4
    Last Post: 11-11-2017, 09:43 PM
  2. Replies: 10
    Last Post: 04-24-2015, 01:28 PM
  3. Replies: 1
    Last Post: 03-12-2015, 03:00 AM
  4. Concatenating fields from matching records
    By MWMike in forum Queries
    Replies: 1
    Last Post: 10-28-2010, 10:49 PM
  5. Concatenating many fields into one field
    By olidav911 in forum Programming
    Replies: 1
    Last Post: 08-13-2009, 05:14 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