?
Solved

Update Inner Join

Posted on 2012-03-22
3
Medium Priority
?
416 Views
Last Modified: 2012-03-22
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 update addressmaster with address updates based on player id?
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
3 Comments
 
LVL 57

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 37753449
try:

update m
set m.street=u.street, m.city=u.city, m.state=u.state, m.zip=u.zip
from addressmaster m inner join Addressupdate u on a.playerid=m.playerid
0
 
LVL 4

Expert Comment

by:petr_hlucin
ID: 37753478
DECLARE @playerId INT
DECLARE @street VARCHAR
DECLARE @city VARCHAR
DECLARE @zip VARCHAR
DECLARE @getAddressUpdate CURSOR
SET @getAddressUpdate = CURSOR FOR
SELECT playerid, street, city, state, zip
FROM AddressUpdate
OPEN @getAddressUpdate
FETCH NEXT
FROM @getAddressUpdate INTO @playerid, @street, @city, @state, @zip
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE AddressMaster
SET street = @street, city = @city, state = @state, zip = @zip
WHERE playerId = @playerId
FETCH NEXT
FROM @getAddressUpdate INTO @playerid, @street, @city, @state, @zip
END
CLOSE @getAddressUpdate
DEALLOCATE @getAddressUpdate
0
 

Author Closing Comment

by:johnnyg123
ID: 37753630
update m<br />set m.street=u.street, m.city=u.city, m.state=u.state, m.zip=u.zip<br />from addressmaster m inner join Addressupdate u on m.playerid=a.playerid
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

777 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