Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rolling up child records into one field. 1

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
How would one roll up multiple records in a child table to one field in a join expression between a parent and child?

e.g.

Select a.name, b.note FROM a LEFT OUTER JOIN b ON a.id = b.fid

Returns, as it should

name1 | note1
name1 | note2
name1 | note3

I want...

name1 | note1,note2,note3

In SQL Server I'd use a user-defined function. Not sure how to do it in Access.


Travis
..with the strength of a grizzly, the reflexes of a puma, and the wisdom of a man.
 
Only small clue I can offer: look up "crosstab query" in Access help - seems like I've seen this stuff on pivot tables before. Sorry I can't be more specific....
Happy Thanksgiving!

The Microsoft mascot is a butterfly.
A butterfly is a bug.
Think about it....
 
I don't think pivots or crosstabs are the thing I'm looking for. This isn't actually aggregation; it's collation.
 
There is a generic concatenate function and sample usage at The same function is probably in the FAQs (with others) in this forum.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks guys.

Oky...big pain in the ass....this is an .mde so I can't save the module. I was originally writing this query to autoupdate an excel sheet. Rather than creating another db and a passthrough, is there a way to do it in Excel, or a long convoluted way directly in sql?
 
If my understanding is correct, the way to do it is by using concatenation:

in EXCEL do it this way:
---------------------------
A B C D E
1 I AM HAPPY =B1&" "&C1&" "&D1
2 NO I AM NOT =B2&"-"&C2&"-"&D2

The result in row 1 will look like this in cell E1:
I AM HAPPY


The result in row will look like this in cell E1:
NO-I AM-NOT

Anything enclosed in quotes is considered a string or text.


IN ACCESS DO IT THIS WAY:
-----------------------
FIELD1
FIELD2
FIELD3 = FIELD1&" "&FIELD2

YOU DON'T ENCLOSE FIELDS IN QUOTES.

I hope this helps.




 
thanks achillese, but I need to concatenate rows, not columns.
 
You can use the pure sql method. Try open Northwind and modify the Category table adding a memo field "AllProducts". Then create an update query with this SQL view:
Code:
UPDATE Categories 
   INNER JOIN Products 
   ON Categories.CategoryID = Products.CategoryID 
SET Categories.AllProducts = [AllProducts] & ", " & [ProductName];
You only need to them remove the first two characters from the AllProducts field to get a comma delimited list of products in each category.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top