Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Merge two tables

Posted on 2004-03-24
5
Medium Priority
?
783 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 70

Accepted Solution

by:
Scott Pletcher earned 200 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

705 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