Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need update TSQL with two tables

Posted on 2016-10-28
3
Medium Priority
?
43 Views
Last Modified: 2016-10-28
Hi

I have two tables, identical structures

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

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

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
0
Comment
Question by:Charles Baldo
[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 Comments
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 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

0
 
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.

UPDATE A
SET A.lanid = B.lanid
FROM tablea A
INNER JOIN tableb B
   ON B.rpn = A.rpn

Open in new window

1
 

Author Closing Comment

by:Charles Baldo
ID: 41864263
That worked, thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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

609 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