SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Simple WHERE condition
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

voyager838
Yak Posting Veteran

90 Posts

Posted - 02/19/2011 :  14:38:05  Show Profile  Reply with Quote
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

Edited by - voyager838 on 02/19/2011 14:38:59

jeffw8713
Aged Yak Warrior

USA
790 Posts

Posted - 02/19/2011 :  15:33:42  Show Profile  Reply with Quote
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 - 02/19/2011 :  16:17:28  Show Profile  Reply with Quote
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

Edited by - voyager838 on 02/19/2011 16:18:58
Go to Top of Page

GilaMonster
Flowing Fount of Yak Knowledge

South Africa
4507 Posts

Posted - 02/19/2011 :  18:14:46  Show Profile  Visit GilaMonster's Homepage  Reply with Quote
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 - 02/19/2011 :  18:55:44  Show Profile  Reply with Quote
Thanks GilaMonster
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000