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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Simple WHERE condition

Author  Topic 

voyager838
Yak Posting Veteran

90 Posts

Posted - 2011-02-19 : 14:38:05
Hello

I 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, B
FROM dbo.T
WHERE A <> ''
AND A IS NOT NULL;

Jeff
Go to Top of Page

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, B
FROM dbo.T
WHERE A <> ''
AND A IS NOT NULL;

Jeff



Hi Jeff

I 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
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page

voyager838
Yak Posting Veteran

90 Posts

Posted - 2011-02-19 : 18:55:44
Thanks GilaMonster
Go to Top of Page
   

- Advertisement -