Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sql Server, Update with many conditions

I have this table called Customers:

id | name | code
----------------
 1 | A    | 1
 2 | B    | 2
 3 | C    | 3
 4 | D    | 4

My idea is to update a list of name like:

A,B,D

With the value 1, and to have:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

id | name | code
----------------
 1 | A    | 1
 2 | B    | 1
 3 | C    | 3
 4 | D    | 1

How can I update code for a list of name?

I could do this:

UPDATE Customers
SET code=1
WHERE name='A'
OR name='B'
OR name='D';

But the list is big, like 45.000 names.

Is there another way to make that querie?

>Solution :

You can do

UPDATE Customers
SET code=1
WHERE name IN ('A', 'B', 'D');

Or if you have too many records maybe something like this would be better :

UPDATE Customers
SET code=1
WHERE name NOT IN ('C','E');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading