473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Invalid use of Null

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
2 17342
-----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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
1
by: Patrick Dunnigan | last post by:
Hi, I am attempting a bulk copy from a c program into SQL Server 2000 using DBLib in freeTDS 0.63 RC11 (gcc 3.4.3, RH 9). I am getting an error message that I cannot find any documentation on. ...
3
by: Frank Perry | last post by:
Howdy, I'm trying to write data out the com port. I have taken the code from the sample on the MSDN Library CD and used the parts that seem relevant. I can open the com port with CreateFile...
0
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. ...
15
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed...
9
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating...
6
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
3
by: rando1000 | last post by:
I'm pulling data from a field on a form, evaluating whether or not it's null, then calculating based on the data in the field. Here's my code for evaluating the field: intAdvanced = IIf(Not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.