Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#279033 - 04/04/2006 14:31 SQL/Access 2003 Query query
Ezekiel
pooh-bah

Registered: 25/08/2000
Posts: 2413
Loc: NH USA
I'm writing a query, and I get odd results. I have a table with several fields. One of these fields is empty in some of the records (about 3500 records). I'm trying to use a Select statement to get the records with the blank field.

I have tried two different methods which <should> give the same number of selected records, but they don't.

In quasi-SQL:
First Method:

Where Field=""

Second Method:

Where Field Is Null

The ="" method yeilds 24 records. The Is Null method yeilds (the correct) 79 records.

Why do these Select modifiers behave differently? Is it an Access bug/oddity?

Baffled,
-Zeke
_________________________
WWFSMD?

Top
#279034 - 04/04/2006 14:37 Re: SQL/Access 2003 Query query [Re: Ezekiel]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4181
Loc: Cambridge, England
Quote:
Why do these Select modifiers behave differently? Is it an Access bug/oddity?

No, that's how SQL is defined. The empty string and NULL aren't the same thing. The empty string means there is a definite value there, which is blank, whereas NULL means there is no value there. Similarly, zero and NULL aren't the same thing in numeric fields.

If any of your 24 blank records appears among your 79 NULL records, then that's an Access bug. If your data is so dirty that both "" and NULL have been used with the same semantic intent, you can either clean it up or use (Field Is NULL or Field = "").

Peter

Top
#279035 - 04/04/2006 15:06 Re: SQL/Access 2003 Query query [Re: peter]
Ezekiel
pooh-bah

Registered: 25/08/2000
Posts: 2413
Loc: NH USA
Peter,
Thanks for the quick answer. I think I get your meaning. I had been using Access' 'filter by' feature to determine the 'correct' number of rows.

Checking for overlap, as you mention - shows that the results from ="" and Is Null are indeed independent data sets (I should have seen that - I still wouldn't have known why though). I guess not all blank fields are created equal!

Thank you very much. The data has now been properly cleaned using:

UPDATE TABLE.FIELD = Null
WHERE (((TABLE.FIELD)=""));

-Zeke
_________________________
WWFSMD?

Top
#279036 - 04/04/2006 20:00 Re: SQL/Access 2003 Query query [Re: Ezekiel]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Which is correct. You really don't want to be storing empty strings ("") in your tables.
_________________________
~ John

Top
#279037 - 05/04/2006 05:26 Re: SQL/Access 2003 Query query [Re: JBjorgen]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
Quote:
Which is correct. You really don't want to be storing empty strings ("") in your tables.


Unless you really do want to be storing empty strings in your tables...
_________________________
-- roger

Top
#279038 - 05/04/2006 10:29 Re: SQL/Access 2003 Query query [Re: JBjorgen]
Ezekiel
pooh-bah

Registered: 25/08/2000
Posts: 2413
Loc: NH USA
How would an empty string get into the table to begin with? Could it get there by deleting pre-existing text from the field?

-Zeke
_________________________
WWFSMD?

Top
#279039 - 05/04/2006 14:41 Re: SQL/Access 2003 Query query [Re: Ezekiel]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
You can certainly INSERT or UPDATE a field with an empty string. Someone put it in there. It may have been something like an automated process that imported data from an external source, and imported empty strings as empty strings rather than checking them to see if they were empty and converting them to NULL.

I don't think that John's assertion that empty strings shouldn't exist is entirely accurate. NULL means that the value does not exist. An empty string means that it does exist, but is blank. I'm trying to come up with a good reason for a difference, and am coming up short. But here's a somewhat questionable example:

Say you're entering people's names into a database, first, middle, and last. You might not have some people's middle names available when you enter the data, so you'd leave them as NULL, meaning that the data does not exist. Later, when completing the data entry, you put in people's middle names, replacing the NULL. But then you come across someone who doesn't have a middle name at all. You might then want to change that field to the empty string, indicating that the value does exist, but it is empty. Of course, all of that is a logical construct. You could conceivably design it to be the other way around. It's all about how you interpret your data. (Though the way I describe makes more sense to me.)

So it's possible that the data you found that had empty strings may have had a different meaning than the data that had NULL values. Or it may have been a data entry error. Only a definition of what the database fields mean for your situtaion can really let us know.
_________________________
Bitt Faulk

Top
#279040 - 05/04/2006 15:50 Re: SQL/Access 2003 Query query [Re: Ezekiel]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
I guess not all blank fields are created equal!
Nope, that's the difference between "blank" and "undefined".
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top
#279041 - 05/04/2006 15:56 Re: SQL/Access 2003 Query query [Re: wfaulk]
JeffS
carpal tunnel

Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
Quote:
So it's possible that the data you found that had empty strings may have had a different meaning than the data that had NULL values
True, though in general (not always) I'd say it's a bad idea to have a design with logic that behaves differently depending on whether a value is blank or null. That usually will result in code that is difficult to understand and maintain.
_________________________
-Jeff
Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.

Top