Solved

Need update TSQL with two tables

Posted on 2016-10-28
3
19 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 19

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Link SQL table to Webpage 9 39
Help with SQL Query 23 39
sql server query? 6 28
Sql query to Stored Procedure 6 20
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now