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

Invalid use of Null

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

How's about:

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

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

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYLVb4echKqOuFEgEQIByACffhHJ4GL6qH5JPidzJ+C16A pUFikAn2JT
lbm9JtWq77n6FFnQVB7nw2XV
=qNxx
-----END PGP SIGNATURE-----
headware wrote:
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?


Nov 13 '05 #2

P: n/a
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

MGFoster <me@privacy.com> wrote in message news:<yz****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

How's about:

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

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

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYLVb4echKqOuFEgEQIByACffhHJ4GL6qH5JPidzJ+C16A pUFikAn2JT
lbm9JtWq77n6FFnQVB7nw2XV
=qNxx
-----END PGP SIGNATURE-----
headware wrote:
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?

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.