By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,790 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,790 IT Pros & Developers. It's quick & easy.

linking on null value fails

P: n/a
Hi,

I have created a very simple query to link two tables on 4 fields.
However, in certain cases, one of the fields used to link the table
may contain nulls (in both tables, so this should still be a match).
Access won't return these records. If the fields are filled with
actual values, everything is fine.

Can somebody help me on this one?

regards,

Larry Peeters:
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It makes sense that Access (JET) does not match on the Nulls. If you think
of Null as meaning Unknown, the matching two things because they are both
Unknown would be wrong.

If your data needs to distinguish between unknown (Null) and
known-to-not-exist (usually represented by a zero-length string), you could
set the Allow Zero Length property of the primary and foreign key fields.
Without testing it, you should find that the ZLSs match, and you can still
have the Nulls that don't. In the real world, this solution would be useful
only in rare cases.

If you have data that needs to be assumed to match on non-null values, you
could use the Nz() function in the FROM clause of the query statement. Open
your query in SQL View, and change the FROM clause to something like this:
FROM Table1 INNER JOIN Table2 ON
CLng(Nz(Table1.ID, 0)) = CLng(Nz(Table2.ID, 0))

The query can no longer be used in Design View, and it will be quite
inefficient to execute, but it should do what you ask.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Larry Peeters" <lp******@primaplan.com> wrote in message
news:70**************************@posting.google.c om...
Hi,

I have created a very simple query to link two tables on 4 fields.
However, in certain cases, one of the fields used to link the table
may contain nulls (in both tables, so this should still be a match).
Access won't return these records. If the fields are filled with
actual values, everything is fine.

Can somebody help me on this one?

regards,

Larry Peeters:

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.