Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace in sql

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-10-15 : 23:01:39
i have 2 tables:

tableA:
ID Code Depart Arrival
10 DoubleAA

tableB:
ID Journey Depart Arrival
10 first UK US
10 second US UK

How can I replace in tableA for NULL Depart and Arrival column to the one in tableB which is the first journey.

expected result:

tableA:
ID Code Depart Arrival
10 DoubleAA UK US

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2013-10-16 : 00:25:22
Select Id
, Code
, Depart = (Select Depart From Table2 Where Journey = 'First')
, Arrival = (Select Arrival From Table2 Where Journey = 'First')
From Table1

veeranjaneyulu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-16 : 02:07:45
[code]
UPDATE a
SET a.Depart = b.Depart,
a.Arrival = b.Arrival
FROM tableA a
INNER JOIN TableB b
ON b.ID = a.ID
AN b.Journey = 'first'
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -