The BIT data type is an integer value that accepts 0, 1, and NULL.
BIT represents a boolean type with TRUE (1) and FALSE (0) values.
String values 'TRUE' and 'FALSE' are also accepted and converted to 1 and 0.
A table with a BIT column.
CREATE TABLE DemoTable
(
Id INT IDENTITY,
MyBoolean BIT
);
GO
INSERT INTO DemoTable VALUES (1);
INSERT INTO DemoTable VALUES (0);
INSERT INTO DemoTable VALUES ('TRUE');
INSERT INTO DemoTable VALUES ('FALSE');
INSERT INTO DemoTable VALUES (NULL);
GO
SELECT * FROM DemoTable;
GO
DROP TABLE DemoTable;
GO
| Id | MyBoolean |
|---|---|
| 1 | 1 |
| 2 | 0 |
| 3 | 1 |
| 4 | 0 |
| 5 | NULL |
| PRODUCT |
|---|
| Id |
| ProductName |
| SupplierId |
| UnitPrice |
| Package |
| IsDiscontinued |
SELECT ProductName, IsDiscontinued
FROM Product
WHERE IsDiscontinued = 'TRUE'
| ProductName | IsDiscontinued |
|---|---|
| Chef Anton's Gumbo Mix | 1 |
| Mishi Kobe Niku | 1 |
| Alice Mutton | 1 |
| Guaraná Fantástica | 1 |
| Rössle Sauerkraut | 1 |
| Thüringer Rostbratwurst | 1 |
| Singaporean Hokkien Fried Mee | 1 |
| Perth Pasties | 1 |
Note: The 'TRUE' boolean string has been converted to 1. BIT values returned from the database are always 0, 1, or NULL.