473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

concatenate two records in same table

Hello,

How do I concatenate two fields in the same table... For example, I
have two tables, first one is called familynametable that has a
familyID and familyname field. This table is connected to a
individualnametable that contains three fields: individualnameID,
FamilyID (to link to familytable) and FirstName.

In the familytable, FamilyID=1, FamilyName=Doe,
In the individualtable there are two records:
IndividualnameID=2, FamilyID=1, and FirstName=Jane
IndividualnameID=2, FamilyID=1, and FirstName=John

We are looking for a way to join by FamilyID the two first names for
mailing purposes:
Jane & John Doe

I have been able to concatenate the fields but I am getting the
following result:
Jane,John Doe
Which is not good for mailing purposes...

Any suggestions?
Thanks
Kevin

Nov 13 '05 #1
2 6737
The SQL gets a little knarly, but here's the idea: Add the individualtable twice, filtering
once for each ordinal name (1 and 2), aliasing the tables as i1 and i2.

The use of the Plus (+) operator will cause the ampersand to dissappear when there is no
second name.

SELECT i1.FirstName & (" & " + i2.FirstName) & " " & familytable.FamilyName As FullName
FROM (familytable INNER JOIN [select FamilyID, FirstName from individualtable
where IndividualnameID=1]. AS i1 ON familytable.FamilyID = i1.FamilyID)
INNER JOIN [select FamilyID, FirstName from individualtable
where IndividualnameID=2]. AS i2 ON familytable.FamilyID = i2.FamilyID

I ran this on test tables and it works, but it assumes that the data in the Individual
table looks like this ...

IndividualnameID FamilyID FirstName
1 1 Danny
2 1 Masha
1 2 Lamont
2 2 Birtha
etc.
--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Kevin" <kz********@marcct.org> wrote ...
Hello,

How do I concatenate two fields in the same table... For example, I
have two tables, first one is called familynametable that has a
familyID and familyname field. This table is connected to a
individualnametable that contains three fields: individualnameID,
FamilyID (to link to familytable) and FirstName.

In the familytable, FamilyID=1, FamilyName=Doe,
In the individualtable there are two records:
IndividualnameID=2, FamilyID=1, and FirstName=Jane
IndividualnameID=2, FamilyID=1, and FirstName=John

We are looking for a way to join by FamilyID the two first names for
mailing purposes:
Jane & John Doe

I have been able to concatenate the fields but I am getting the
following result:
Jane,John Doe
Which is not good for mailing purposes...

Any suggestions?
Thanks
Kevin

Nov 13 '05 #2
Ooops ... that second table should be LEFT joined, or else you'll only
get records that have one of each names ...

SELECT i1.FirstName & (" & " + i2.FirstName) & " " & familytable.FamilyName As FullName
FROM (familytable INNER JOIN [select FamilyID, FirstName from individualtable
where IndividualnameID=1]. AS i1 ON familytable.FamilyID = i1.FamilyID)
LEFT JOIN [select FamilyID, FirstName from individualtable
where IndividualnameID=2]. AS i2 ON familytable.FamilyID = i2.FamilyID

When Birtha is removed from the Cranston family (divorce is always ugly)
then the output looks like this ...

FullName
--------------------------------
Danny & Jill Lesandrini
Lamont Cranston

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
1
by: Big Time | last post by:
I've got a crosstab query that counts the number of values in one of my tables. However, rather than giving me the number of instances of each record, what I would like is for each value to...
1
by: Kevin | last post by:
Hello, How do I concatenate two fields in the same table... For example, I have two tables, first one is called familynametable that has a familyID and familyname field. This table is connected...
4
by: jpr | last post by:
hello, I have a form with four fields: Fname, Lname, DOB and txtresult. Examples: JOHN, SMITH, 03/19/2006. The first three are bound to a table while the txtresult is unbound. I would...
2
by: perryche | last post by:
Bear with me since I know very limited knowledge about VBA and Module... I have a table Employees, where I build a query out of based on TeamID=1, Therefore, only listed those employees that...
4
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
6
by: drazenj | last post by:
Hi , sorry for my english ... I work in high school as a teacher and try to make CLASS SCHEDULE (TIME schedule) for my collegues and for students . My problem is that I don't know how to...
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
6
by: mark83anthony | last post by:
How do I concatenate strings from a column into a single row? Whats the logic to create the function in DB2. Given is below. Color ------ red orange
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.