SQL Toggle True/False Status Identification field

Source: Internet
Author: User

Requirement: Use a SQL (SQL SERVER) statement to implement a value that reverses the State identity field (type bit). That is, from true to false, or from false to true.

Scheme:

First, determine the original value of this field, and then update to the opposite value.
Second, to the database bit type assignment, in the management interface input and the use of SQL statement to operate a different . The admin interface input must be true or FALSE, and the SQL statement will be 0 or 1.

Practice:
UPDATE attusers SET IsActive =isactive+1 WHERE id=1
SELECT * from Attusers WHERE id=1

IsActive Field remains 1


What if we use a minus sign? Practice:

UPDATE attusers SET IsActive =isactive-1 WHERE id=1
SELECT * from Attusers WHERE id=1

You can find that each time the result is switched between 0 and 1, SQL Server handles 1 as one.

SQL Toggle True/False Status Identification field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.