• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 51
  • Last Modified:

Need update TSQL with two tables

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
Charles Baldo
Asked:
Charles Baldo
1 Solution
 
Dustin SaundersDirector of OperationsCommented:
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
 
Daniel Van Der WerkenIndependent ConsultantCommented:
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
 
Charles BaldoSoftware DeveloperAuthor Commented:
That worked, thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now