2012-01-13 4 views
1

TSQLのWHERE文で論理比較をTRUEまたはFALSEにする方法はありますか?私は論理比較の結果がFALSEでチェックできるように、私はこのクエリを達成することができますどのように

SELECT * 
FROM table1 
INNER JOIN table2 ... 
INNER JOIN table3 ... 
INNER JOIN table4 ... 
WHERE ((table1.Value IS NULL) AND 
     (table2.Value IS NULL) AND 
     (table3.Value IS NULL) AND 
      (table4.Value IS NULL)) -- Here I want to ADD something like IS FALE; 
            --How can I do this? 

答えて

3

あなたはいくつかのオプション

ませを持って

SELECT * 
FROM table1 
INNER JOIN table2 ... 
INNER JOIN table3 ... 
INNER JOIN table4 ... 
WHERE NOT ((table1.Value IS NULL) AND 
      (table2.Value IS NULL) AND 
      (table3.Value IS NULL) AND 
      (table4.Value IS NULL) 
     ) 
2

をオペランドないで使用

...(Table4.value IS NOT NULL)...
あなたは...NOT (Table4.value IS NULL)...

CASE

CASE WHEN (<complex comparison> = somevalue THEN 1 ELSE 0) = 0

0

を意味するか:

SELECT * 
FROM table1 
INNER JOIN table2 ... 
INNER JOIN table3 ... 
INNER JOIN table4 ... 
WHERE (
     NOT( 
     (table1.Value IS NULL) AND 
     (table2.Value IS NULL) AND 
     (table3.Value IS NULL) AND 
     (table4.Value IS NULL) 
     ) 
    ) 
関連する問題