473,394 Members | 1,750 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,394 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 6742
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.