?
Solved

Insert new records

Posted on 2012-03-22
4
Medium Priority
?
295 Views
Last Modified: 2012-03-23
I have 2 tables on sql server 2008 database

with same fields


Playerid, street, city, state, zip

AddressMaster has master list of addresses

Addressupdate has address updates

How do I  insert addresses in address updates that are not in address master?
0
Comment
Question by:johnnyg123
[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
4 Comments
 
LVL 58

Expert Comment

by:HainKurt
ID: 37753729
try:

insert into AddressMaster
select * from Addressupdate where playerid not in (select playerid from AddressMaster)
0
 
LVL 58

Expert Comment

by:HainKurt
ID: 37753734
this may perform better

insert into AddressMaster
select * from Addressupdate u left join AddressMaster m on u.playerid=m.playerid
where m.playerid is null
0
 
LVL 6

Accepted Solution

by:
netjgrnaut earned 2000 total points
ID: 37753766
INSERT INTO AddressMaster (Playerid, street, city, state, zip)
SELECT Playerid, street, city, state, zip FROM AddressUpdate
WHERE NOT EXISTS (
SELECT m.Playerid, m.Street, m.City, m.State, m.Zip
FROM AddressMaster m
INNER JOIN AddressUpdate u ON m.Playerid = u.Playerid AND
     m.Street = u.Street AND
     m.City = u.City AND
     m.State = u.State AND
     m.Zip = u.Zip
)
0
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 37753771
(From the way you asked the question, I'm assuming that some of the data in AddressUpdate is already in AddressMaster.  Otherwise the simple SELECT statments will work fine.)
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

762 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