A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Concatenate multiple records



 
 
Thread Tools Display Modes
  #1  
Old March 4th, 2010, 12:43 AM posted to microsoft.public.access.queries
QB
external usenet poster
 
Posts: 150
Default Concatenate multiple records

I have a table to enter contact information where each contact is assigned a
random id no. That said it is possible to also associate a Family id no so
you can link members of the same family together. I now need to pull a
singular list by family id with the relevant info combining multiple records
together and am lost on the how-to do it.

Basic Table Structure
Table Name: C1
Table Fields: ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...

The ID is the PK and the M_MNBR is the family id.

I need to pull the a list
C_NAME, M_TITLE, M_FNAME, M_LNAME, M_ADDR, ...
but, and you knew there'd be a twist. I need to always group by the Title =
"Mr".

Therefore, if in a given family there is an entry for Mr John Smith and
another for Mrs Joan Smith I need it to return a concatenated C_Name Mr John
Smith and Mrs Joan Smith and then the rest of the data pertaining to only Mr
John Smith.

If in the case there is no Mr, then give the Mrs info, and vice-versa.

A concrete example
ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...
1, 10001, Mr, Smith, John, Mr John Smith,...
2, 13092, Mrs, Libeler, Lilian, Mrs Lilian Libeler,...
3, 14560, Dr, Krawl, David, Dr David Krawl,...
4, 10001, Mrs, Smith, Gwen, Mrs Gwen Smith,...

The query would return
Mr John Smith and Mrs Gwen Smith, Mr, Smith, John, ...
Mrs Lilian Libeler, Mrs, Libeler, Lilian, ...
Dr David Krawl, Dr, Krawl, David, ...

Can this be done and how?

Thank you for the help,

QB
  #2  
Old March 4th, 2010, 02:24 AM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Concatenate multiple records

See:
Concatenate values from related records
at:
http://allenbrowne.com/func-concat.html

After copying the function, you'll need to use an expression like this:
=ConcatRelated("Trim([M_TITLE] & "" "" & [M_FNAME] & "" "" & [M_LNAME])",
"SomeTable", "FamilyID = " & Nz([FamilyID],0)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"QB" wrote in message
...
I have a table to enter contact information where each contact is assigned
a
random id no. That said it is possible to also associate a Family id no
so
you can link members of the same family together. I now need to pull a
singular list by family id with the relevant info combining multiple
records
together and am lost on the how-to do it.

Basic Table Structure
Table Name: C1
Table Fields: ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...

The ID is the PK and the M_MNBR is the family id.

I need to pull the a list
C_NAME, M_TITLE, M_FNAME, M_LNAME, M_ADDR, ...
but, and you knew there'd be a twist. I need to always group by the Title
=
"Mr".

Therefore, if in a given family there is an entry for Mr John Smith and
another for Mrs Joan Smith I need it to return a concatenated C_Name Mr
John
Smith and Mrs Joan Smith and then the rest of the data pertaining to only
Mr
John Smith.

If in the case there is no Mr, then give the Mrs info, and vice-versa.

A concrete example
ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...
1, 10001, Mr, Smith, John, Mr John Smith,...
2, 13092, Mrs, Libeler, Lilian, Mrs Lilian Libeler,...
3, 14560, Dr, Krawl, David, Dr David Krawl,...
4, 10001, Mrs, Smith, Gwen, Mrs Gwen Smith,...

The query would return
Mr John Smith and Mrs Gwen Smith, Mr, Smith, John, ...
Mrs Lilian Libeler, Mrs, Libeler, Lilian, ...
Dr David Krawl, Dr, Krawl, David, ...

Can this be done and how?

Thank you for the help,

QB


  #3  
Old March 4th, 2010, 01:44 PM posted to microsoft.public.access.queries
QB
external usenet poster
 
Posts: 150
Default Concatenate multiple records

Allen,

But how does the function deal with leading the concatenation with the Mr
entry and follow with the Mrs entry?

QB





"Allen Browne" wrote:

See:
Concatenate values from related records
at:
http://allenbrowne.com/func-concat.html

After copying the function, you'll need to use an expression like this:
=ConcatRelated("Trim([M_TITLE] & "" "" & [M_FNAME] & "" "" & [M_LNAME])",
"SomeTable", "FamilyID = " & Nz([FamilyID],0)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"QB" wrote in message
...
I have a table to enter contact information where each contact is assigned
a
random id no. That said it is possible to also associate a Family id no
so
you can link members of the same family together. I now need to pull a
singular list by family id with the relevant info combining multiple
records
together and am lost on the how-to do it.

Basic Table Structure
Table Name: C1
Table Fields: ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...

The ID is the PK and the M_MNBR is the family id.

I need to pull the a list
C_NAME, M_TITLE, M_FNAME, M_LNAME, M_ADDR, ...
but, and you knew there'd be a twist. I need to always group by the Title
=
"Mr".

Therefore, if in a given family there is an entry for Mr John Smith and
another for Mrs Joan Smith I need it to return a concatenated C_Name Mr
John
Smith and Mrs Joan Smith and then the rest of the data pertaining to only
Mr
John Smith.

If in the case there is no Mr, then give the Mrs info, and vice-versa.

A concrete example
ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...
1, 10001, Mr, Smith, John, Mr John Smith,...
2, 13092, Mrs, Libeler, Lilian, Mrs Lilian Libeler,...
3, 14560, Dr, Krawl, David, Dr David Krawl,...
4, 10001, Mrs, Smith, Gwen, Mrs Gwen Smith,...

The query would return
Mr John Smith and Mrs Gwen Smith, Mr, Smith, John, ...
Mrs Lilian Libeler, Mrs, Libeler, Lilian, ...
Dr David Krawl, Dr, Krawl, David, ...

Can this be done and how?

Thank you for the help,

QB


.

  #4  
Old March 4th, 2010, 04:14 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Concatenate multiple records

It doesn't. You'll need to write your own function if you want to combine
names.

In my experience, that's not a good idea. You'll end up with nonsense
because you cannot accurately interpret all the kinds of human relationships
that exist, and you cannot programmatically combine the names in all the
possible ways that could need to be handled.

If it matters, then you probably need to teach your database about
households: who makes them up, and how they should be addressed. He's an
introduction to such a concept:
People in households and companies - Modeling human relationships
at:
http://allenbrowne.com/AppHuman.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"QB" wrote in message
...
Allen,

But how does the function deal with leading the concatenation with the Mr
entry and follow with the Mrs entry?

QB





"Allen Browne" wrote:

See:
Concatenate values from related records
at:
http://allenbrowne.com/func-concat.html

After copying the function, you'll need to use an expression like this:
=ConcatRelated("Trim([M_TITLE] & "" "" & [M_FNAME] & "" "" & [M_LNAME])",
"SomeTable", "FamilyID = " & Nz([FamilyID],0)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"QB" wrote in message
...
I have a table to enter contact information where each contact is
assigned
a
random id no. That said it is possible to also associate a Family id
no
so
you can link members of the same family together. I now need to pull a
singular list by family id with the relevant info combining multiple
records
together and am lost on the how-to do it.

Basic Table Structure
Table Name: C1
Table Fields: ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR,
...

The ID is the PK and the M_MNBR is the family id.

I need to pull the a list
C_NAME, M_TITLE, M_FNAME, M_LNAME, M_ADDR, ...
but, and you knew there'd be a twist. I need to always group by the
Title
=
"Mr".

Therefore, if in a given family there is an entry for Mr John Smith and
another for Mrs Joan Smith I need it to return a concatenated C_Name Mr
John
Smith and Mrs Joan Smith and then the rest of the data pertaining to
only
Mr
John Smith.

If in the case there is no Mr, then give the Mrs info, and vice-versa.

A concrete example
ID, M_MNBR, M_TITLE, M_LNAME, M_FNAME, C_NAME, M_ADDR, ...
1, 10001, Mr, Smith, John, Mr John Smith,...
2, 13092, Mrs, Libeler, Lilian, Mrs Lilian Libeler,...
3, 14560, Dr, Krawl, David, Dr David Krawl,...
4, 10001, Mrs, Smith, Gwen, Mrs Gwen Smith,...

The query would return
Mr John Smith and Mrs Gwen Smith, Mr, Smith, John, ...
Mrs Lilian Libeler, Mrs, Libeler, Lilian, ...
Dr David Krawl, Dr, Krawl, David, ...

Can this be done and how?

Thank you for the help,

QB


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.