Reputation: 35
I have list of the column in single table which I want to update to some else.
Table name:HyundaiRaw_New_april
Original:
HART 2008-A
HART 2009-A
HART 2010-A
HART 2010-B
HART 2011-A
HART 2011-B
HART 2011-C
HART 2012-A
HART 2012-B
HART 2012-C
HART 2013-A
I want the above thing to be updated as 'ABC 2008-A
'. I want HART to be replaced with "ABC"
I tried updating using the below query
update HyundaiRaw_New_april
set deal='HART 2009-A','HART 2010-A','HART 2010-B'
where DEAL='ABC 2009-A','ABC 2010-A','ABC 2010-B'
and
update HyundaiRaw_New_april
set deal=HART 2009-A,HART 2010-A,HART 2010-B
where DEAL=ABC 2009-A,ABC 2010-A,ABC 2010-B
it does not work
Upvotes: 0
Views: 60
Reputation: 69504
update HyundaiRaw_New_april
SET DEAL = CASE WHEN DEAL = 'ABC 2009-A' THEN 'HART 2009-A'
WHEN DEAL = 'ABC 2010-A' THEN 'HART 2010-A'
WHEN DEAL = 'ABC 2010-B' THEN 'HART 2010-B'
END
You also add a default value using ELSE
clause in your CASE statement when no condition is met the column will be updated to default value mentioned in ELSE clause.
Upvotes: 0
Reputation: 473
It should work for you...
UPDATE TABLENAME
SET COLUMNNAME = REPLACE(COLUMNNAME,'oldValue','newValue');
Upvotes: 0
Reputation: 18629
Please try:
update
HyundaiRaw_New_april
set DEAL=REPLACE(DEAL, 'HART', 'ABC')
Upvotes: 1