Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

UPDATE RIA.Contact SET title = REPLACE(title, 'Cheif', 'Chief') where title rlike 'Cheif';
UPDATE RIA.Contact SET title = REPLACE(title, 'Manger', 'Manager') where title rlike 'Manger';
UPDATE RIA.Contact SET title = REPLACE(title, 'Manging', 'Managing') where title rlike 'Manging';
UPDATE RIA.Contact SET title = REPLACE(title, 'Excutive', 'Executive') where title rlike 'Excutive';

Can we merge the above 4 to something like this : UPDATE table SET A = IF(A > 0 AND A < 1, 1, IF(A > 1 AND A < 2, 2, A)) WHERE A IS NOT NULL;

I know we can do this using a procedure but is it possible just using a query?

I tried this -

UPDATE RIA.Contact SET title = IF(title rlike 'Cheif', replace(title,'Cheif','Chief'), IF(title rlike 'Manger', replace(title,'Manger','Manager'))) WHERE title rlike 'Cheif' or title rlike 'Manger';

no go!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
466 views
Welcome To Ask or Share your Answers For Others

1 Answer

UPDATE RIA.Contact
SET title = REPLACE(
  REPLACE(
    REPLACE(
      REPLACE(title, 'Excutive', 'Executive'),
      'Manging', 'Managing'),
    'Manger', 'Manager'),
  'Cheif', 'Chief')
WHERE title rlike 'Cheif'
   OR title rlike 'Manger'
   OR title rlike 'Manging'
   OR title rlike 'Excutive';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...