Solved

MS Access concatenate across records

Posted on 2014-01-31
6
229 Views
Last Modified: 2014-03-26
I have a table that contains customer ID's, order numbers and part numbers.

I need to identify orders that are identical across customers to make ordering groups of parts easier.

E.g. Cust 1 orders parts 7, 11 and 4 in a batch.  How many times has that combination been ordered?

Ideally I see this as creating a field that contains the 3 fields in numerical order separated by a delimiter and then counting across records.

In the attached file I would expect


20,304,1626                  2 records
20,304,988,1626           1 record
20,304,1911                  2 records
unique-orders.xls
0
Comment
Question by:hwassinger
  • 3
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
Gozreh earned 500 total points
ID: 39824992
i wrote for you a function in VBA
MS-Access-concatenate-across-rec.accdb
0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39825065
Maybe something like this?

- Requires the records to be sorted into orders (i.e. by customer, then order, then part).
- Incrementally build each order in col D
- Pick out only complete orders in col E
example.xls
0
 

Author Comment

by:hwassinger
ID: 39825212
@ Gozreh, That is EXACTLY what I want, what do I need to do to make this work with my actual database?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 10

Expert Comment

by:Gozreh
ID: 39825275
please explain the structure of your database, or upload some sample
0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39825679
This works in SQL Server. I don't have access to hand, not sure if CROSS APPLY is legal in Access.
If it works you can do the whole thing directly in SQL :)
SELECT cust_num, order_num, part_codes = MAX(SUBSTRING(combined.code_list, 3, 1000))
FROM your_table AS e
CROSS APPLY (
    SELECT ', ' + CAST(part_code AS nvarchar(10))
    FROM your_table AS i
	WHERE e.cust_num = i.cust_num AND e.order_num = i.order_num
	ORDER BY part_code ASC
	FOR XML PATH ('')
) AS combined (code_list)
GROUP BY cust_num, order_num
ORDER BY cust_num, order_num

Open in new window


SQL query that directly aggregates orders
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39833348
Hi @hwassinger, did you resolve this question?
if not, please explain the structure of your database, or upload some sample, so i can try to help it work with your actual database.

the solution from @Angelp1ay will not work in a access database, only if you are using SQL server.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now