Solved

Update Inner Join

Posted on 2012-03-22
3
406 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 53

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 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

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

740 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