Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add/Change records to a new table from other table

Author  Topic 

Carmbruster
Starting Member

1 Post

Posted - 2009-03-12 : 16:29:02
Hello - I'm new to SQL so bear with me. But I have searched all over and cannot find out how to do something that seems very basic to me.

I have 10 tables that are all identical in their layout that hold an inventory database with snapshots of quantity on hand at a particular time.

I would like to combine these 10 tables into 1 newtable that has a different layout that simply has
Part#, qty1, qty2, qty3, qty4.....qty10
where qty1 is the qty from table1, qty2 is the qty from table2, etc.

Part #'s are added and removed randomly so each table will not always have the same number of records.

The problem that I'm having is that sometimes the part# will already exist in the newtable so I need to do an update to that record instead of an insert and I cannot seem to get this to work.

Basically, I start with table1 and insert that entire table into newtable. Then, I'd like to read table2 and if the record exists, copy the quantity from table2 into the newtable into the qty2 variable. If the record does not exist, insert it into the newtable and copy the quantity from table2 into the newtable into the qty2 variable. Then, I'd like to repeat this process for all of the tables.

My end result would be that newtable would have all of the parts that exist in tables 1 - 10 and their corresponding qty's from each of the individual tables.

I'm using MySQL 4.1.

Any suggestions would be greatly appreciated!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-12 : 16:57:40
quote:
Originally posted by Carmbruster

I'm using MySQL 4.1.
Try www.dbforums.com



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -