Link to home
Start Free TrialLog in
Avatar of bruno71
bruno71Flag for United States of America

asked on

Combine multiple different Access tables into 1 table

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
ASKER CERTIFIED SOLUTION
Avatar of Dulton
Dulton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bruno71

ASKER

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.
Avatar of Dulton
Dulton

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.
Avatar of Jeffrey Coachman
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?
Avatar of bruno71

ASKER

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.
Then see  Dulton's first  post
Avatar of bruno71

ASKER

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.