Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / November 2004

Tip: Looking for answers? Try searching our database.

Invalid use of Null

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
headware - 29 Oct 2004 23:20 GMT
I'm getting a weird problem in an Access query. I have a table that
contains a field calle F1 that's a 2 character text field. The first
character is always a number. What I'd like to do is find all the
records in which F1 has an even number in the first position. I first
tried this:

SELECT F1
FROM Table1
WHERE Nz(F1, '') <> '' AND (CInt(Left(F1, 1)) Mod 2 = 0)

This gave me the error "Invalid use of null". I figured this didn't
work because some of the F1 entries are blank and SQL doesn't short
circuit AND statements, so it's trying to take the Left of a blank
field. So I tried breaking it up into more than one query. I created a
query called qryA that went like this:

SELECT Left(F1, 1) AS F1Char1
FROM Table1
WHERE Nz(F1, '') <> '';

Then I created another query like this:

SELECT *
FROM qryA
WHERE CInt(F1Char1) Mod 2 = 0

Still get "Invalid use of null".

The funny part is that if I do this:

SELECT CInt(F1Char1) Mod 2 = 0
FROM qryA

It works. No invalid null. I guess that's not really that funny. But
here's something that *is* funny: if I run the following query it
works!

SELECT *
FROM qryA
WHERE (CInt(F1Char1) Mod 2 = 0) LIKE '-1'

Why would it work using LIKE? What's going on here?

Thanks,
Dave
MGFoster - 30 Oct 2004 00:42 GMT
How's about:

SELECT Left(F1,1) AS F1Char1
FROM Table1
WHERE F1 IS NOT NULL
  AND Val(Nz(F1,0)) MOD 2 = 0

Signature

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

> I'm getting a weird problem in an Access query. I have a table that
> contains a field calle F1 that's a 2 character text field. The first
[quoted text clipped - 38 lines]
>
> Why would it work using LIKE? What's going on here?
headware - 04 Nov 2004 21:16 GMT
Thanks, that worked perfectly. I guess this must come down to how the
Val function handles null or blank data. It looks as if it returns 0
in that case.

Dave

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 48 lines]
> >
> > Why would it work using LIKE? What's going on here?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.