Need update TSQL with two tables

Posted on 2016-10-28
Last Modified: 2016-10-28

I have two tables, identical structures

CREATE TABLE [dbo].[TempA](
      [RPN] [int] NULL,
      [LanID] [nvarchar](50) NULL

CREATE TABLE [dbo].[TempB](
      [RPN] [int] NOT NULL,
      [LanID] [nvarchar](50) NULL

In TableA  LanID  is blank
In TableB Every LanID has a value

I need an TSQL UPDATE that will update the value of TableA.LanID  from TableB.LanID only when the RPN is equal in both

Thank You
Question by:Charles Baldo
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
LVL 12

Accepted Solution

Dustin Saunders earned 500 total points
ID: 41864243
Something like this would work:
UPDATE tablea
SET tablea.lanid = tableb.lanid
from tablea
inner join tableb
ON tableb.rpn = tablea.rpn

Open in new window

LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 41864260
Essentially the same as Dustin Saunders said, but with table aliases, which I like a lot.

SET A.lanid = B.lanid
FROM tablea A
   ON B.rpn = A.rpn

Open in new window


Author Closing Comment

by:Charles Baldo
ID: 41864263
That worked, thanks

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show RTF format in an SSRS report 3 44
SQL Server 2008 Std. License Key owner or vendor 4 56
SQL works but want to get the XML node data separately 11 30
Need SSIS project 2 29
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

733 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