How do I update a table column in order to revert its value(set true if value is false and false for true! null remains null).
Please exclude solutions where one uses case when
or IIF()
I want something like following
UPDATE mytable SET IsEditable = !IsEditable
The SQL NOT condition (sometimes called the NOT Operator) is used to negate a condition in the WHERE clause of a SELECT, INSERT, UPDATE, or DELETE statement.
If you've opened a table and you want to clear an existing value to NULL, click on the value, and press Ctrl + 0 .
For any situation with three possible values, the bit datatype can be utilized by leveraging NULL as a logical value. If "not answered" and "not applicable" need stored along with "yes" and "no", a char or tinyint becomes necessary. Detecting NULLs requires a special syntax in the WHERE clause: IS [NOT] NULL.
A simple method to toggle a bit column (MySQL, SQL Server, and others) As you can see, the XOR operator returns “0” if the two arguments match and “1” if they don't. This makes it easy to flip the bit in a boolean column without having to first check it's existing value.
You can use bitwise NOT operator:
update mytable set IsEditable = ~IsEditable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With