Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select by joining NULL value with NULL value? 1

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Joined
Jan 26, 2006
Messages
392
Location
US
Hello. In SQL 2000...

I am running a select statement..

I am Joining:
DB2 tbldocumentinfo to DB1
DB2 tblland to DB2 tbldocumentinfo
DB2 tblacreage to DB2 tblland

Code:
select col002, col029, col032, col33, srange, stownship,  sdocumentno, DB2..tblland.szcomment 
from DB1
left join DB2..tbldocumentinfo 
     on col002 = DB2..tbldocumentinfo.sdocumentno
left join DB2..tblland 
     on DB2..tbldocumentinfo.irecordid = DB2..tblland.irecordid
          and ltrim (DB2..tblland.stownship) = col032 
          and ltrim (DB2..tblland.srange) = col033 
          and (DB2..tblland.szcomment) = col029
left join DB2..tblacreage 
     on DB2..tblacreage.ilandid = DB2..tblland.ilandid

This script works, however, I'm wondering if there is a way to use the line:
and (DB2..tblland.szcomment) = col029
to join where the value in DB2..tblland.szcomment is NULL and COL029 is NULL?

When I run the script as is I get about 3000 rows. If I take that line out I get about 11,000 rows becuase of the NULL values.

I'm hoping to join that field based on NULL as well so all 11,000 rows come up joined together properly.

Thanks for looking!
 
You could use the ISNULL() function and set both to an empty value depending of the type of the field type, something like:
Code:
and ISNULL(DB2..tblland.szcomment,'') = ISNULL(col029,'')


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks Borislav. That worked perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top