Solved

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

Posted on 2010-11-30
4
354 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
  • 3
4 Comments
 

Author Comment

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

Accepted Solution

by:
GSGDBA earned 250 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

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…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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
Viewers will learn how the fundamental information of how to create a table.

747 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

16 Experts available now in Live!

Get 1:1 Help Now