Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
voyager838
Yak Posting Veteran
90 Posts |
Posted - 2011-02-19 : 14:38:05
|
HelloI want filter an table where its not contain any NULL value or empty '' value.Here is the query:select [A], [B]from dbo.[T]where ([A] != '') OR ([A] IS NOT NULL) It doesn't work.What have i missing ??Someone?thanks |
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2011-02-19 : 15:33:42
|
What do you mean it doesn't work? Are you getting an error or invalid results?If you don't want any row where A is either '' or Null, then you need to use AND:SELECT A, BFROM dbo.TWHERE A <> '' AND A IS NOT NULL;Jeff |
|
|
voyager838
Yak Posting Veteran
90 Posts |
Posted - 2011-02-19 : 16:17:28
|
quote: Originally posted by jeffw8713 What do you mean it doesn't work? Are you getting an error or invalid results?If you don't want any row where A is either '' or Null, then you need to use AND:SELECT A, BFROM dbo.TWHERE A <> '' AND A IS NOT NULL;Jeff
Hi JeffI didn't get some error, but it didn't simple get some expected result.However You solve it. Thanks. I dont know why and how, but when you use OR instead of AND it simple didn't.Why ?/Voyage |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-02-19 : 18:14:46
|
Simple boolean logic. An OR returns true if either condition is true. Since it is impossible for a value to both = '' and be NULL, there is no way that both conditions can be false. Hence all rows will qualify for that predicate--Gail ShawSQL Server MVP |
|
|
voyager838
Yak Posting Veteran
90 Posts |
Posted - 2011-02-19 : 18:55:44
|
Thanks GilaMonster |
|
|
|
|
|