Solved

Update Inner Join

Posted on 2012-03-22
3
403 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
3 Comments
 
LVL 51

Accepted Solution

by:
HainKurt 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

821 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