Solved

Merge two tables

Posted on 2004-03-24
5
740 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:
ScottPletcher 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

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.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

943 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now