Of course, the first reaction is to use a stored procedure. Determine the original value of this field, and then update.
A rough search on the web did not find a solution. I have a very interesting result when I do it, and I don't even have a where.
The bit type assignment to the database is done using SQL statements and different input from the admin interface. Admin interface input must be filled in with true or false. And the SQL statement uses 0 or 1
So, first try:
Copy Code code as follows:
Updat T set b=b+1 where id=1;
Select B from t where id=1;
b field has been kept 1
So with the minus sign?
Copy Code code as follows:
Update T set b=b-1 where id=1;
Select B from t where id=1;
You can see that each result is switched between 0 and 1, and SQL Server treats-1 as a handle.
The demand was easily solved.
This is usually used where some state switches (or switches) are needed, and there is no need to know what happens after the switch in the requirements. Very interesting and very simple, hehe