嗨,我學到了sql server的BIT
有真,假,未知。例如,比較1 > NULL
產生unknown
。如何在sql server的布爾中訪問UNKNOWN?
我知道我可以間接檢查一下:如果x is null or y is null
,那麼比較x > y
必須是unknown
。
有沒有辦法直接訪問unknown
?例如
select *
into #t
from (
SELECT 1 as [x], 1 as [y] UNION ALL
SELECT 1 as [x], 2 as [y] UNION ALL
SELECT 1 as [x], NULL as [y]
) as a
SELECT *
from #t
--x y
--1 1
--1 2
--1 NULL
select *
,/* ???? */ as [is x > y]
from #t
--want to have:
--x y is x > y
--1 1 0
--1 2 0
--1 NULL unknown
我認爲「未知」表示爲NULL。 –