Solved

Combine multiple different Access tables into 1 table

Posted on 2013-06-27
7
1,236 Views
Last Modified: 2013-07-08
I have an Access database with many small tables.  I would like to combine those tables into one large table.  The tables all have different fields.  I don't need to just view the data together with a query...I need to actually collect the data into one table.

Is there a way to combine Access tables into 1 and have it create the fields based on the original tables?  For example, if the source field name doesn't exist in the destination table, it will create it.  If the source field name already exists (there may be duplicates), it just appends to that field in the destination table.

For bonus points, would it be possible to insert a field that contains the name of the original table that the data came from?

See the attached picture for a very simple example.
table-example.jpg
0
Comment
Question by:bruno71
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
Dulton earned 500 total points
ID: 39282390
I can't say I agree with what you're trying to do, but here's how you could do it.



SELECT
"Table 1" As [OrgSource]
,[first name]
,[last name]
,[number]
,null AS [color]
,null AS [type]
,null AS [size]
INTO [NewTable]
FROM Table1
UNION SELECT
"Table 2"
,null
,null
,null
,[color]
,[type]
,null
FROM Table2
UNION SELECT
"Table 3"
,null
,null
,[number]
,null
,null
,[size]
FROM Table 3;
0
 

Author Comment

by:bruno71
ID: 39282404
I know I could do it manually, but is there a more automated way of doing it?  I suppose I could just create the new table with every field and map the fields one by one, but I was hoping for a quicker, less tedious solution.
0
 
LVL 6

Expert Comment

by:Dulton
ID: 39282416
That code above will query the 3 tables you have and SELECT INTO a new table... all of your data will be in the new table in your requested layout.

If you run that code in a SQL query window, you should end up with your new table just as you want it, fully populated.

I don't know of any wizards or anything to do what you're trying to do, effectively de-normalizing tables...

the code I gave you is as 'automated' of a way as I'm aware of in terms of not only creating the table, but populating it too.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39286188
Not sure I understand what the "resultant" table will represent?
Each record would be "what?"

How are you sure that "Green" should not be the color for the second record in the resultant table?

Can you first explain what the data in each table represents and how they are related?
Also explain what combining all the table will achieve?
0
 

Author Comment

by:bruno71
ID: 39290103
The problem is that the data in all the tables is not related.  Things were originally setup (by someone else) in a bunch of different tables, when really things could have been in the same table.  

Also, field naming is not consistent across the tables.  There may be fields that do have the same name (like 'number' in the example) so I can put that data in the same column.  But then one table might have a field called 'size' and another table has a field called 'dimensions' when really they are the same thing.

I want to combine all the table structures and data into one table so that I can sort through and consolidate it all.  I was just looking for an easy way to combine everything instead of building the master table one field/record at a time.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39292181
Then see  Dulton's first  post
0
 

Author Closing Comment

by:bruno71
ID: 39307049
Well, I guess it was a long shot to find something as easy as I was looking for.  Dulton's solution would work, especially if I needed to do it frequently.  But this was a one-time thing.

I did find that it is possible to move the data, table by table, by doing copy/paste with Excel as an intermediary.  I could select the whole table in Access and copy/paste the data into Excel in text format.  Then I could rearrange the columns in Excel to match the columns in the SQL table.  Then I could copy/paste the data rows from Excel into SQL (SSMS) and it would insert the individual rows as new records.  

Thanks for all the help.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question