0

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

2
  • And THAT's why you need to normalize your tables... Commented Apr 3, 2014 at 11:11
  • set deal='HART 2009-A','HART 2010-A','HART 2010-B' is invalid SQL Commented Apr 3, 2014 at 11:16

3 Answers 3

1

Please try:

update 
  HyundaiRaw_New_april
set DEAL=REPLACE(DEAL, 'HART', 'ABC')
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, the above query worked... how do you do when..its is all random alphabet, in this case it was "HART", how do you do?
0

It should work for you...

UPDATE TABLENAME
SET COLUMNNAME = REPLACE(COLUMNNAME,'oldValue','newValue');

Comments

0
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.