SET ANSI_NULLS OFF
似乎取決於是否你是從一個表或值進行比較的字段得到不同的結果在TSQL。任何人都可以幫助我理解爲什麼最後2個查詢沒有結果?我不是在尋找解決方案,只是一個解釋。ANSI_NULLS如何在TSQL中工作?
select 1 as 'Col' into #a
select NULL as 'Col' into #b
--This query gives results, as expected.
SET ANSI_NULLS OFF
select * from #b
where NULL = Col
--This query gives results, as expected.
SET ANSI_NULLS OFF
select * from #a
where NULL != Col
--This workaround gives results, too.
select * from #a a, #b b
where isnull(a.Col, '') != isnull(b.Col, '')
--This query gives no results, why?
SET ANSI_NULLS OFF
select * from #a a, #b b
where a.Col != b.Col
--This query gives no results, why?
SET ANSI_NULLS OFF
select * from #a a, #b b
where b.Col != a.Col
我剛剛偶然發現這一點,我覺得就我以前從來不知道這一點。我一直認爲SQL的行爲方式與在Java/.NET中對NULL進行比較的方式相同。 – 2012-03-01 07:12:47