Solved

Update Inner Join

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

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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

920 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

13 Experts available now in Live!

Get 1:1 Help Now