473,394 Members | 2,002 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.

Combine Tables

Sal
Sorry for the vague subject, not sure how to properly sum up what I need to
do.

I have 2 tables

Tbl1 is single field:

CODE

2115-GOR
2115-JUN

it is always in that format with a "-" seperating a prefix and a suffix

Tbl2 has 2 fields:

CODE|ID

2115|S
2115|M
2115|L
2115|XL

What I need to do is take the value that comes before the "-" in TBL1 and
whenever it is found in Tbl2 my result is like this (in a 3rd table or in
one of the original 2, it doesn't really matter)

CODE|ID

2115-GOR|
2115-GOR|S
2115-GOR|M
2115-GOR|L
2115-GOR|XL
2115-JUN|
2115-JUN|S
2115-JUN|M
2115-JUN|L
2115-JUN|XL

So it would write a first record of the CODE from TBL1 (ID field stays
blank) and then a record of the CODE and matching ID value from TBL2.

I hope that made sense. The way I described it in words might not have but
hopefully the starting and end point examples did.

Thanks much.
May 11 '06 #1
2 1772
Sal
That's a pipe character jammed in there as field seperator. I'll add some
spaces for easier reading:

Tbl1 is single field:

CODE

2115-GOR
2115-JUN

it is always in that format with a "-" seperating a prefix and a suffix

Tbl2 has 2 fields:

CODE | ID

2115 | S
2115 | M
2115 | L
2115 | XL

What I need to do is take the value that comes before the "-" in TBL1 and
whenever it is found in Tbl2 my result is like this (in a 3rd table or in
one of the original 2, it doesn't really matter)

CODE|ID

2115-GOR |
2115-GOR | S
2115-GOR | M
2115-GOR | L
2115-GOR | XL
2115-JUN |
2115-JUN | S
2115-JUN | M
2115-JUN | L
2115-JUN | XL

So it would write a first record of the CODE from TBL1 (ID field stays
blank) and then a record of the CODE and matching ID value from TBL2.

I hope that made sense. The way I described it in words might not have but
hopefully the starting and end point examples did.

Thanks much.
May 11 '06 #2
Sa**@nospam.com (Sal) wrote in
news:97*******************@216.196.97.136:
That's a pipe character jammed in there as field seperator.
I'll add some spaces for easier reading:

Tbl1 is single field:

CODE

2115-GOR
2115-JUN

it is always in that format with a "-" seperating a prefix and
a suffix

Tbl2 has 2 fields:

CODE | ID

2115 | S
2115 | M
2115 | L
2115 | XL

What I need to do is take the value that comes before the "-"
in TBL1 and whenever it is found in Tbl2 my result is like
this (in a 3rd table or in one of the original 2, it doesn't
really matter)

CODE|ID

2115-GOR |
2115-GOR | S
2115-GOR | M
2115-GOR | L
2115-GOR | XL
2115-JUN |
2115-JUN | S
2115-JUN | M
2115-JUN | L
2115-JUN | XL

So it would write a first record of the CODE from TBL1 (ID
field stays blank) and then a record of the CODE and matching
ID value from TBL2.

I hope that made sense. The way I described it in words might
not have but hopefully the starting and end point examples
did.

Thanks much.


start with a query that calculates just the part before the
dash, and includes the code.
If this is always 4 characters that can be as simple as
BaseNumber: LEFT([code],4)

the SQL would be
SELECT CODE, LEFT([code],4) as basenumber form tbl1;

If it's variable, you will need to replace the 4 with some code
that determines where, the dash is.
Basenumber: left([code],instr("-",[code]))

If you have the possibility that there is no dash at all, you
will have to filter out the no dash codes.

THEN use the query and tbl2 to create another query that joins
on query.basenumber and tbl2.code, and concatenates query.code
and tbl2.ID, using the & operator.

SQL:
SELECT query.code & tbl2.ID AS FullCode from Query INNER JOIN
tbl2 ON tbl2.CODE = query.basenumber;

Now create a union query to add in the tbl1.code

SQL:
SELECT FULLCODE from Query2 UNION SELECT CODE from tbl1;

Use this query as the source for a maketable query.

You need a third table as the number of records is greater that
from either table.

--
Bob Quintal

PA is y I've altered my email address.
May 11 '06 #3

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

Similar topics

1
by: snOOp | last post by:
I am trying to combine the data from two similar tables into one query, but I need for all of the records from both tables to show up and I want the ones that have matching 'emplid' to be combined...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
1
by: mojo | last post by:
We have set up an Access database with tables x,y, & z where we would like to have multiple people entering data into a table x. Each person has an identical copy of the database on their PC's. ...
2
by: Reidar Jorgensen | last post by:
I have several Access databases, identical in structure, but different data. Is there an easy way to combine them all into one database? There are six tables, I just want the data from all...
1
by: Red | last post by:
So I inherited this db that has multiple 'orders' tables. Each order table is name for the year of the orders... i.e. 2005 is 'Orders-2005', 2006 is "Orders-2006" So, I am not allowed to...
1
by: Roy | last post by:
No errors here, I'm just looking for ways to make my code more efficient. As the subject line suggests, I have a LOT of repeaters on a certain page. They are visible or hidden depending on user...
1
by: Lars E. | last post by:
Hi all. I am trying to combine data from 2 tables in one datagridview. I have tables: "Customer" and "CustomerContact". I want to display Customer information (displaying all fields in...
2
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq...
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
3
by: stateemk | last post by:
Hi, I'm probably making this much harder than it needs to be, but I just can't think of how to do this. Each year, a database is created with all employees on it. I need to pull all the employees...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.