?
Solved

How to update MS SQL table 2 with data from table 1 matched by key ?

Posted on 2010-11-30
4
Medium Priority
?
380 Views
Last Modified: 2012-08-13
I am using MS SQL 2002 R2
I have 2 tables. I wish to update 4 fields from table 2 into same named columns in table 1 where they match on another field.
Table one [ONSGBGeog] has many fields of GIS data. I have created new columns DESCRIPTION, INDEX_LOCAL, INDEX_NATIONAL, DISTRICT.
Table 2 [DESIR] has same 4 named fields.
Match is where OUTAREA_ID in Table 2 (Key) matches COA_CODE in table1  (non-key).

THX
0
Comment
Question by:kabutz
[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
4 Comments
 

Author Comment

by:kabutz
ID: 34239074
Its MS SQL 2008 R2  - sorry typo
0
 
LVL 3

Accepted Solution

by:
GSGDBA earned 750 total points
ID: 34239840
Hi Kabutz,

If you are trying to update table 2 data from table 1 based on key. Query is as below.

Update t2
set
t2.col1=t1.col_X  
from table1 t1, table2 t2 where t1.key1=t2.key1

Refer below link for more details:
http://msdn.microsoft.com/en-us/library/aa260662(SQL.80).aspx

0
 

Author Comment

by:kabutz
ID: 34246445
Excellent - it solved the problem.
0
 

Author Closing Comment

by:kabutz
ID: 34652935
zzz
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

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