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

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
kabutzAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GSGDBAConnect With a Mentor Commented:
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
 
kabutzAuthor Commented:
Its MS SQL 2008 R2  - sorry typo
0
 
kabutzAuthor Commented:
Excellent - it solved the problem.
0
 
kabutzAuthor Commented:
zzz
0
All Courses

From novice to tech pro — start learning today.