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 and Update records

Author  Topic 

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2011-10-19 : 22:41:47
Guys,

I need to replace the records from MyTable2 of RMA_TYPE_ID.
I will look the ESN from Mytable1 to Mytable2 if exist. if found i will replace RMA Type ID of MyTable2 by 10.
how to make this in script. im trying to look for sample here in the forum but i coundnt found.
i need your help guys.

kindly modified this script. thanks.

Select t1.esn, t1.rma_type_id
from MyTable1 as t1
left Outer Join Mytable2 as t2
on t2.esn = t1.esn


MYTABLE1
ESN--RMA TYPE ID
------------------
000100005534710-10
000100006163690-10
000100007779690-10
000100007928690-10


MYTABLE2
ESN--RMA_TYPE_ID
------------------
000100005534710--2
000100006163690--2
000100007779690--2
000100007928690--2

Thank you in Advance.

Jonel

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2011-10-19 : 23:13:32
I tried this script. it;s working.

Update chrisMartin.dbo.ESNRMAs
SET RMA_type_id=10
where esn in ('000100005534710',
'000100006163690',
'000100007779690',
'000100007928690')
and RMA_TYPE_ID='2'

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-20 : 00:23:49
so you want to look only for the above esns? the below would be more generic soln

UPDATE t2
SET t2.RMA_TYPE_ID = t1.RMA_TYPE_ID
FROM MyTable1 as t1
INNER Join Mytable2 as t2
on t2.esn = t1.esn



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2011-10-20 : 00:47:59
Thanks you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-20 : 01:01:45
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -