In MSSQL, bit-type field updates are always performed by first checking and then updating. In this way, you need to query the updates first and then execute the updates.
Suddenly think of whether it is possible to directly update it, each time get the opposite value before the update.
The first thought was to use mid, and later found that MID was not supported in SQL statements.
Data shows: "mid is a PB function. Generally, the database should use the substr function"
Later, I found the "substring" function, which has the same usage as mid, so I have the following method.
Update anketo1 set Fb = substring ('10', FB + 1,1) Where id = 5
Later, I asked BM, and BM said that the reverse request would be taken directly.
Update anketo1 set Fb = ~ FB where id = 5
I told BM to use substring.
BM said: "This guy is amazing. This can also be thought out. This is an evil martial arts ."
Finally, we can use ABS to obtain the absolute value.
Update anketo1 set Fb = ABS (fb-1)
No matter what martial arts, winning is a good martial arts.
The above three methods are all good methods.
Appendix:
Substring
Returns a part of a character, binary, text, or image expression. For more information about valid Microsoft & reg; SQL Server & #8482; data types that can be used with this function, see data types.
Syntax
Substring (expression, start, length)
Parameters
Expression
Is a string, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.
Start
It is an integer that refers to the starting position of the stator string.
Length
It is an integer that refers to the length of the substring (the number of characters to return or the number of bytes ).
ABS Functions
Returns the absolute value of a number.
ABS (number)
The number parameter can be any valid numeric expression. If the number contains null, null is returned. If it is a non-initialized variable, 0 is returned.
Description
The absolute value of a number is the unsigned value. For example, ABS (-1) and ABS (1) Both return 1.
The following example uses the ABS function to calculate the absolute value of a number:
Dim mynumber
Mynumber = ABS (50.3) 'returns 50.3.
Mynumber = ABS (-50.3) 'returns 50.3.