Solved

Need update TSQL with two tables

Posted on 2016-10-28
3
28 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:charlesbaldo
3 Comments
 
LVL 12

Accepted Solution

by:
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

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:charlesbaldo
ID: 41864263
That worked, thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

828 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