Solved

Insert new records

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Abstract Express Replacement Software 12 28
SSIS with VPN COnnection 2 77
Inserting oldest record into new table. 5 25
Rename a column in the output 3 14
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

810 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