1

table1(id int,name VC,description VC); のようなテーブルがあります。このテーブルには数百のレコードが含まれています。説明列には、いくつかの空白と null 値があります。説明値が Null または空白である行を削除したいですか?

私はこのようにしてみました

select * from table1 where description not in('',NULL); //Displaying nothing

But

select * from table1 where description in('',NULL);// It is displaying all the rows which contains white spaces but not Nulls

私は混乱しています。IN 演算子は varchar も受け入れます。NOT を使用しない場合は正しい結果が得られますが、NOT を使用すると得られないのはなぜですか。

前もって感謝します..

4

4 に答える 4

2

これを試して:

select * from table1 where description not in('') and description is not null;

于 2012-12-06T09:37:31.067 に答える
1

null 値を比較するには IS NOT NULL を使用する必要があります

select * from table1 where description is not null and description <> ''
于 2012-12-06T09:38:42.407 に答える
0

これを試すことができます-これはc#.IsNullOrWhitespaceに似ています

SELECT * FROM Table1 WHERE Description IS NOT NULL AND LEN(TRIM(Description)> 0)

于 2012-12-06T09:41:27.907 に答える
0

SQL "IN" 条件は、複数の SQL "OR" 条件を使用する必要性を減らすのに役立つためです。

だから、書く:

description not in('',NULL);

それは同じです:

!(description='' OR description is NULL)

書くことは同じです:

!(description='') AND description is not NULL
于 2012-12-06T09:39:41.840 に答える