Solved

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

Posted on 2010-11-30
4
374 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 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
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

689 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