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?