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)
 NULL on

Author  Topic 

seware
Starting Member

11 Posts

Posted - 2011-10-03 : 16:51:41
Using 2008 R2...

If I join a lookup table to anoher "main" table using a left outer join, and there is no matching row in the lookup table, the result will be a NULL entry for each field included from the lookup table. If I am using WHERE statement of "lookupfield1 <> 1", to filter out lookup rows with that field's value of '1', doesn't the case I described first (no matching row and thus NULL) satisfy "<> 1"

Or is there no comparison performed because the field is NULL?

Am I going to need to check for NULL and <> 1 in order for a "main" table record without a matching lookup record to be included?

probably a newbie question... but I'm a bit confused.

Thanks.


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-03 : 16:58:01
Sounds like you need to move lookupfield1 <> 1 to the join condition. If that doesn't work, please explain the issue with sample data/expected result set.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-03 : 16:58:39
If it does work, you can read up on this here: http://www.sqlteam.com/article/additional-criteria-in-the-join-clause

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

seware
Starting Member

11 Posts

Posted - 2011-10-03 : 17:15:02
That's it exactly! Thanks so very much.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-03 : 17:24:07
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -