Solved

SQL Update

Posted on 2012-03-27
3
395 Views
Last Modified: 2012-03-27
Hi,

I have two tables --

CREATE TABLE [dbo].[Member-Address](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[MemberID] [nvarchar](50) NULL,
	[ClubName] [nvarchar](50) NULL,
	[Address1] [nvarchar](255) NULL,
	[Address2] [nvarchar](255) NULL,
	[Town] [int] NOT NULL,
	[Region] [int] NOT NULL,
	[Locality] [int] NOT NULL,
	[Country] [int] NOT NULL,
	[PostCode] [nvarchar](10) NULL

Open in new window


AND

CREATE TABLE [dbo].[addressupload](
	[MemberID] [int] NULL,
	[Town ID] [float] NULL,
	[RegionID] [float] NULL,
	[LocalityID] [float] NULL,
	[CountryID] [float] NULL,
	[Postcode] [nvarchar](10) NULL,
	[ExchequerID] [nvarchar](10) NULL
) ON [PRIMARY]

Open in new window



I need to update the [Town], [Region], [Locality], [Country], [PostCode] values for each record in [dbo].[Member-Address] with the values in [dbo].[addressupload] where [dbo].[addressupload].[MemberID] is equal to [dbo].[Member-Address].[MemberID]

I'm not so sure how to do this..

Grateful for any assistance -

Thanks
0
Comment
Question by:garethtnash
3 Comments
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 250 total points
ID: 37771993
UPDATE t
SET t.Town=v.[Town ID],
      t.Region=v.RegionID,
... etc
FROM [Member-Address] t
INNER JOIN addressupload v
ON t.MemberID=v.MemberID
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 250 total points
ID: 37772004
update ma
set ma.<col> = au.<col>
from Member-Address ma
join addressupload au on
ma.MemberID = au.memberID
0
 

Author Closing Comment

by:garethtnash
ID: 37772224
Thank you
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

803 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