Solved

Insert new records

Posted on 2012-03-22
4
236 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

757 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

17 Experts available now in Live!

Get 1:1 Help Now