2013年6月18日 星期二

Access and SQL Server Views with Boolean Values; when is True -1 or 1

參考引用:Access and SQL Server Views with Boolean Values; when is True -1 or 1 (10th February 2010)
--
 CREATE TABLE BooleanTest(
AnId INT IDENTITY(1,1) PRIMARY KEY,
ABoolean BIT,
ADescription VARCHAR(50)
)
GO

INSERT INTO BooleanTest(ABoolean,ADescription)
VALUES (1,'This is true')
GO

INSERT INTO BooleanTest(ABoolean,ADescription)
VALUES (0,'This is false')
GO

INSERT INTO BooleanTest(ADescription)
VALUES ('This is null')
GO

-- False Test
SELECT * FROM BooleanTest
WHERE ABoolean = 0
GO

-- True Test
SELECT * FROM BooleanTest
WHERE ABoolean = 1
GO

-- NULL Test
SELECT * FROM BooleanTest
WHERE ABoolean IS NULL
GO

沒有留言:

張貼留言