Solved

Merge two tables

Posted on 2004-03-24
5
762 Views
Last Modified: 2008-03-03
I have 2 tables in 2 separate databases called Authors with the following fields:
-AuthId(Identity Field)
-Fname
-Lname

The tables contain book authors from all over the world. One of the tables is North America and the other table is authors from rest of the world. There are many Authors with the same FName and Lname. The only way they are identified is by the Author. Now I want to merge this two tables with a Stored Procedure.

How do I do This??
0
Comment
Question by:AutomaticSlim
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dhenson
ID: 10673118
Just for clarification....

Your not looking for a sql to join the two tables together in one result set, but rather a Stored Procedure to create an additional table (dropping if exists) that has all the records from both original tables?

Is that correct?
0
 
LVL 2

Expert Comment

by:dhenson
ID: 10673122
Also....

Did the seeds for the two tables overlap so that the AuthID's would not necessarily be unique?

dhenson
0
 

Author Comment

by:AutomaticSlim
ID: 10673307
Here is an Example:

Authtable1
Id     Fname      LName
1      James       Robertson
2      Mark         Jackson
3      Janet        Ciega


Authtable2
Id     Fname      LName
1      Adam       Pictch
2      Will          Steiner
3      Will          Steiner
4      James       Robertson

Note that James Roberston in Table2 is not same person as James Robertson in Table1.
Now I want to add Authtable2 to Authtable1


Thanks
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 50 total points
ID: 10680586
This should do it:

INSERT INTO Authtable1 (FName, LName)
SELECT FName, LName
FROM OtherdbName.dbo.Authtable2


If you want, add a column to the original table for the old AuthId so you can link back to the old table:

ALTER TABLE AuthTable1
ADD OldAuthId INT

Then:

INSERT INTO Authtable1 (FName, LName, OldAuthId)
SELECT Fname, LName, AuthId
FROM OtherdbName.dbo.Authtable2
0
 

Author Comment

by:AutomaticSlim
ID: 10689910
what you suggested above works but now the relationships between my other tables gets unstable and some other issues that I didn't think of.
I guess I asked a question without thinking about it properly.........

Thanks for the help
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

821 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