Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to 'toggle' a bit field (0 or 1)

Status
Not open for further replies.

stevelionbird

Programmer
Jul 21, 2006
21
US
Hi everyone,

I'm looking for a way with one statement to change the value of a tinyint field (named 'is_archive') in a table to either:

zero if its current value is one
OR
one if its current value is zero

Is there a way to do this without having to first query the table to get the current value of 'is_archive'?

e.g.
Code:
update [i]table[/i] set is_archive = (is_archive = 1) ? 0 : 1 where [i]conditions[/i];

Thanks in advance,
Steve
 
Try the NOT operator
Code:
update table set is_archive = NOT(is_archive) where conditions;
See for details

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top