DenaliHardtail
DenaliHardtail

Reputation: 28306

how to use SQL to alter a field value?

How do I use SQL to flip the value of a bit for rows meeting certain criteria?

For example, my SQL is

SELECT * from Attributes WHERE (IsValid = 'TRUE')

This query gives me all the records where I want to flip the IsValid bit. Now that I have the rows, I want to flip the bit to FALSE. How do I do this?

Upvotes: 2

Views: 124

Answers (4)

Mark Byers
Mark Byers

Reputation: 838326

Use an UPDATE statement:

UPDATE Attributes SET IsValid = 'FALSE' WHERE IsValid = 'TRUE'

Note that if the only two possible values for this field are TRUE and FALSE then you are effectively setting all rows to 'FALSE' which is equivalent to not using a WHERE clause (although the performance characteristics may be different):

UPDATE Attributes SET IsValid = 'FALSE'

Upvotes: 2

JNK
JNK

Reputation: 65157

UPDATE Attributes
SET IsValid = 'FALSE'
WHERE IsValid = 'TRUE'

Upvotes: 0

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181290

Do this:

update Attributes set IsValid = 'FALSE' where IsValid = 'TRUE';

Upvotes: 0

Brad Christie
Brad Christie

Reputation: 101614

UPDATE Attributes
SET    IsValid = 'FALSE'
WHERE  IsValid = 'TRUE';

That what you need?

Upvotes: 3

Related Questions