Solved

Update Inner Join

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 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

22 Experts available now in Live!

Get 1:1 Help Now