Concatenate multiple records


Q

QB

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
 
Ad

Advertisements

A

Allen Browne

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)
 
Q

QB

Allen,

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

QB





Allen Browne said:
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

Reply to group, rather than allenbrowne at mvps dot org.


QB said:
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

.
 
Ad

Advertisements

A

Allen Browne

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

Reply to group, rather than allenbrowne at mvps dot org.


QB said:
Allen,

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

QB





Allen Browne said:
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

Reply to group, rather than allenbrowne at mvps dot org.


QB said:
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

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top