473,624 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining Multiple Rows of one Field into One Result

15 New Member
I have a multi relationship database and I'm pulling the company's contact info, queryied if they are a grower, and a resulting list of their products by catgeory. I need to have the products listed all together in one field.

Example:

Expand|Select|Wrap|Line Numbers
  1. CompanyName        Grower    Category    Product
  2. B Orchard            -1    Fruits        Apples
  3. B Orchard            -1    Fruits        Blackberries
  4. B Orchard            -1    Vegetables    Beans
  5. B Orchard            -1    Vegetables    Other
  6. B Orchard            -1    Vegetables    Peas
  7. B Orchard & Roadside Market -1    Fruits        Apples
  8. B Orchard & Roadside Market -1    Fruits        Blackberries
  9. B Orchard & Roadside Market -1    Vegetables    Beans
  10. B Orchard & Roadside Market -1    Vegetables    Beets
  11. B Orchard & Roadside Market -1    Vegetables    Broccoli
  12. B Orchard & Roadside Market -1    Vegetables    Peppers
  13. B Star Acres        -1    Vegetables    Asparagus
  14. B Star Acres        -1    Vegetables    Beans
  15. B Star Acres        -1    Vegetables    Beets
  16. B Farms            -1    Fruits        Blackberries
  17. B Farms            -1    Fruits        Melons
  18. B Farms            -1    Fruits        Watermelons
  19. B Farms            -1    Vegetables    Beans
  20. B Farms            -1    Vegetables    Broccoli
  21. B Farms            -1    Vegetables    Cabbage

Desired output:
Expand|Select|Wrap|Line Numbers
  1. CompanyName        Grower Category Product, Product, Product
  2. B Orchard            -1    Fruits Apples, Blackberries
  3. B Orchard            -1    Vegetables Beans, Other, Peas
  4. B Orchard & Roadside Market -1    Fruits Apples, Blackberries
  5. B Orchard & Roadside Market -1    Vegetables Beans, Beets, Broccoli, Peppers
  6. B Star Acres        -1    Vegetables Asparagus, Beans, Beets
  7. B Farms            -1    Fruits Blackberries, Melons, Watermelons
  8. B Farms            -1    Vegetables Beans, Broccoli, Cabbage

Even Better if it made a new column for the different Categories/corresponding product, but beggars can't be choosers, I'll go for the first chance, at least.

Utopia Output:
Expand|Select|Wrap|Line Numbers
  1. CompanyName        Grower    Category Product(s)    Category Product(s)
  2. B Orchard            -1    Fruits Apples, Blackberries Vegetables Beans, Other, Peas
  3. B Orchard & Roadside Market -1    Fruits Apples, Blackberries Vegetables    Beans, Beets, Broccoli, Peppers
  4. B Star Acres        -1    Vegetables Asparagus, Beans, Beets
  5. B Farms            -1    Fruits    Blackberries, Melons, Watermelons Vegetables Beans, Broccoli, Cabbage
I'm using access 2002 on xp.
Jan 18 '07 #1
46 30844
cyberdwarf
218 Recognized Expert New Member
Hi,

You could try using an adodb recordset and looping thru, concatenating the products for each grower as you go

Is this for display purposes/export to Excel?

HTH

Steve
Jan 18 '07 #2
kyjabber
15 New Member
Hi,

You could try using an adodb recordset and looping thru, concatenating the products for each grower as you go

Is this for display purposes/export to Excel?

HTH

Steve
Yes, this is for display purposes/export to Excel. I'm having to generate this for another function to a contracter. My other option was to hand merge them in Excel with a macro.

Unforunately my coding is very rusty, and I'm not very experienced in SQL or VBA. (Want to learn but manager won't send me to training :|, well he woudl but our IT staff won't approve.long story.)
Jan 18 '07 #3
cyberdwarf
218 Recognized Expert New Member
If you are competent in Excel, then that will be the quickest solution.

Otherwise you have a sharp learning-curve and not much time!

Steve
Jan 18 '07 #4
kyjabber
15 New Member
If you are competent in Excel, then that will be the quickest solution.

Otherwise you have a sharp learning-curve and not much time!

Steve
We'll... I've never been afraid to learn. I've seen several VBA and SQL scripts accomplishing something and I'm trying them out, but no luck so far.

The excel Macro is annoying b/c I have to select each section and I have over 350 companies to go through and 3K products collectively.

Thanks away, but I'll take any suggestions that I can get.

~Anna
Jan 18 '07 #5
NeoPa
32,567 Recognized Expert Moderator MVP
Excel may be easier (with formulas rather than bit-by-bit) but in Access you could look at a Cross-Tab Query.
Jan 19 '07 #6
kyjabber
15 New Member
Excel may be easier (with formulas rather than bit-by-bit) but in Access you could look at a Cross-Tab Query.
How would you suggest with formulas? each Company has a different of products and category mixes and a number of records?

What I posted was an exert of a query that does contain data from three different tables (one is a pass through table that give the product its ID).

I can post an excel file that shows the results of the query and what I've done by hand. I just *know* there has to be an easier (and quicker way) to do this and unfortunately even though I have a concept of what can be done I lack the skills to do that on my own (but I'm really liking the topics in this forum so hopefully over time I can keep improving my skills.

I saw this thread: Combining Rows-Opposite of Union, and thought it was similar, but I haven't figured out the syntax yet for my own fields (and I'm really going at this blind. srsly, I know enough to be dangerous, but I do understand the concepts). and wasn't sure how to do the stings for three fields/columns.
Jan 19 '07 #7
NeoPa
32,567 Recognized Expert Moderator MVP
I'd forgotten I'd already posted that solution in code.
In that case, you're better off using a derivative of that.
Let me know where you got stuck.
Jan 19 '07 #8
NeoPa
32,567 Recognized Expert Moderator MVP
I can possibly go through the Excel one later when less busy - but thinking about it - it is more complicated than I thought to explain :(
Jan 19 '07 #9
kyjabber
15 New Member
I'm not sure how to post attachments. Sorry to be such a n00b!

Here's what I got in the module thus far, but I know I don't all three fields represented and I hadn't figured it out yet (was looking for examples and reading to know what I was doing... )

I don't know what to do with the field Category yet.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'Concat Returns Products
  3. 'listed by company
  4. Public Function Concat(strCompanyName As String, _
  5.                        strProduct As String) As String
  6.     Static strLastCompanyName As String
  7.     Static strProducts As String
  8.  
  9.     If strCompanyName = strLastCompanyName Then
  10.         strProducts = strProducts & ", " & strProduct
  11.     Else
  12.         strLastCompanyName = strCompanyName
  13.         strProducts = strProduct
  14.     End If
  15.     Concat = strProducts
  16. End Function
  17.  
And here's what I put in the SQL Query
Once again, I need to add the Catgeory field for it to select. (and once I know how to add additional fields to this then maybe I can add the FNAME, LNAME, addy fields? or I'll just c/p into the excel sheet I have to have.

Expand|Select|Wrap|Line Numbers
  1. SELECT CompanyName, Max(Concat(CompanyName,Product)) AS Products
  2. FROM t_CompanyCategoriesProducts
  3. GROUP BY CompanyName;
Oh and to possibly make life simpler for me, I c/p the query results into a new Table (t_CompanyCateg oriesProducts), so that I'll have a static set to work with to get this going (and hopefully simplify in the mean while. And that table only has those three fields.

Thank you again, so much. I feel like I'm making progress. :)
Jan 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4356
by: ameshkin | last post by:
I know this is probably not too hard to do, but how do I display multiple rows of a mysql query/recordset. Im having trouble doing this. I don't just want to display them, but I want to make sure ONE field in each row gets a variable. The table name is RecentUploads, the field I want to pull is XML This is probably something simple that is more experienced, but I've only been doing this for a couple of months. Any help would be...
5
1516
by: BerkshireGuy | last post by:
I was searching the threads about combing multiple rows into one and found some good stuff, but need your help to expand on it. I have a table as follows Policy Number DateOfTrans TransType BenefitAmt 1234 12/1/2006 Received $12,000 1234 12/3/2006 Approved $5,000 1234 12/5/2006 Paid $5,000
7
43133
by: Mintyman | last post by:
Hi, I'm working on a system migration and I need to combine data from multiple rows (with the same ID) into one comma separated string. This is how the data is at the moment: Company_ID Material 0x00C00000000053B86 Lead 0x00C00000000053B86 Sulphur 0x00C00000000053B86 Concrete
14
2606
by: jackiefm | last post by:
I realize the thread I am responding to was posted in January but I am basically having the same issue. I am not familiar with VBA but use Access daily. I have written simple scripts but nothing to write home about. I followed the previous thread and my situation is very similar. I have an application with users. These users have access to multiple terminals. I am trying to combine the TerminalName field with all terminals the user has access...
3
3097
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
In my project,i added datagridview to my form , i transfered my table to datagridview and added multiple rows and when i called dataadapther.update ,,result is ok. But when i tried it for the delete operations,i got the error like "set primary key in your table" ,,i want delete multiple rows from Datatable which doesnt contain primary key
3
3912
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is messing up. Problems:
3
5014
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a user (eg txtRDateStart & txtRDateEnd). The script was envisaged to be able to also gather a time and text description that would be repeated within each row. For example: The user would enter... Start Date: 13/03/2010 End Date: 17/03/2010...
7
4498
by: CoachDave48 | last post by:
I am a rookie coder and got some great help from Marcus last year so I thought I would make another request. I am trying to retrieve all boys in one household into a form and edit the individual rows and then update with one submit button. I can retrieve the rows and populate the form but the update does not work. Thanks in advance Here is the testing code obtained from http://www.phpeasystep.com/mysql/10.html
6
10894
by: Jeremy Goodman | last post by:
Access 2007; Merging records containing multivalue drop down lists. I have a database showing legislation information divided by State/territory. The database needs to be able to show the info from each legislation and then an overall picture for the state. There is no problem with merging some of the info using the steps in: http://bytes.com/topic/access/answers/589999-combining-multiple-rows-one-field-into-one-result The problem is...
0
1666
by: Sravanthip | last post by:
Hello, I am working on Crystal reports Xi.I am creating one formula using split function.I have to display the result in multiple rows.Example: If address has Multiple Lines split it based on Space(any delimiter)then display in differrent rows for particular row. Like that i have container Numbers concatenated with &.I have to display them in multiple rows one by one on record basis. Here is my code: whileprintingrecords; Stringvar...
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.