[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-30
4
Medium Priority
?
385 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

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.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

649 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