• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Insert new records

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
johnnyg123
Asked:
johnnyg123
  • 2
  • 2
1 Solution
 
HainKurtSr. System AnalystCommented:
try:

insert into AddressMaster
select * from Addressupdate where playerid not in (select playerid from AddressMaster)
0
 
HainKurtSr. System AnalystCommented:
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
 
netjgrnautCommented:
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
 
netjgrnautCommented:
(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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now