Reputation: 28306
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
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
Reputation: 181290
Do this:
update Attributes set IsValid = 'FALSE' where IsValid = 'TRUE';
Upvotes: 0
Reputation: 101614
UPDATE Attributes
SET IsValid = 'FALSE'
WHERE IsValid = 'TRUE';
That what you need?
Upvotes: 3