-1

I would like to UPDATE sql by using "except" Conditions but it's not working.

This is sql query that I have used:

UPDATE `LMS_EMP` SET `email`="XXX@xXX.com" WHERE NOT `org_abbr_code` IN (HR100, HR101, HR103);

Here are my concept:

1.If some of fields org_abbr_code have these values HR100 OR HR101 OR HR103, the email field will not change.

2.If another org_abbr_codevalues, the email field will change as expect.

Thank you very much for any suggestion.

**I've edited for readable.

4 Answers4

2

Following query will be helpful to you,

UPDATE LMS_EMP SET email="XXX@xXX.com" WHERE org_abbr_code NOT IN ("HR100", "HR101", "HR103");
Abhilash Ravindran C K
  • 1,818
  • 2
  • 13
  • 22
2
UPDATE LMS_EMP SET email="XXX@xXX.com" WHERE org_abbr_code NOT IN ("HR100","HR101", "HR103");
Krunal Shah
  • 836
  • 8
  • 25
1

As Gordon Linoff said, don't forget the single quote :

UPDATE `LMS_EMP` 
SET `email`='XXX@xXX.com' 
WHERE `org_abbr_code` NOT IN ('HR100', 'HR101', 'HR103');
Daniel E.
  • 2,440
  • 1
  • 14
  • 24
-1

Same query i have added below

UPDATE LMS_EMP SET email="XXX@xXX.com" WHERE org_abbr_code NOT IN ("HR100", "HR101", "HR103");

Normally you want to use double quotation while you are adding any thing in NOT IN or IN statement or else it will throw an error

Aravindhan R
  • 270
  • 5
  • 26
  • Thanks! @Aravindhan. I will keep in mind. – user9111600 Feb 27 '18 at 13:48
  • Don't it's not true : https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql – Daniel E. Feb 27 '18 at 13:50
  • @DanielE. In some software like teradate will not support single quotation for set of character. Single quotation will support for numbers . In my experience i am tell this thing and i have worked on above statement by using single quotation – Aravindhan R Feb 27 '18 at 13:54
  • It's software specific who doesn't follow the SQL specification a string should be Single Quote. And for example in ORACLE a double quote will bring you an error. – Daniel E. Feb 27 '18 at 13:55
  • @DanielE. Thanks! Daniel to share another knowledge. – user9111600 Feb 27 '18 at 13:58
  • @DanielE. As you have posted the query it throwing error for this user. He is already tried by suggestion based on gordon lifoff. It's not working for him – Aravindhan R Feb 27 '18 at 13:59
  • the misplaced "not" ;) – Daniel E. Feb 27 '18 at 14:00