Solved

Insert new records

Posted on 2012-03-22
4
268 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
  • 2
  • 2
4 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 37753729
try:

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

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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

856 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