Records not matching with Criteria (1 Viewer)

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
Hello All,

I'm running a very simple query where I only want the preferred address for a particular record. There is a Short Text field named "Preferred" populated with either "Y" or "N"

My query is as follows

Select *
FROM Table
WHERE Preferred = "Y";
---------------------------------------------
Why am I getting records in my results set where the Preferred = N?

I even tried
Select *
FROM Table
WHERE Preferred <>"N";
----------------------------------
Yet Preferred = N is still included in the results set. I want these excluded. How do I do so?


Thanks in advance for any help.
 

plog

Banishment Pending
Local time
Today, 05:28
Joined
May 11, 2011
Messages
11,646
If you want Preferred to contain only 2 values, it should be a Yes/No data field. Sounds like its text.

"N " <> "N"
"N\t" <> "N"
"N\n" <> "N"

You could have a space, a tab or a return character in that string field. Yes/No fields won't accomodate "hidden" characters. Add a calcualted field to that last query:

PLength: Len([Preferred])

Then see what the length is of those seemingly "N" values. Greater than 1 and that means you have a hidden character.
 

Ranman256

Well-known member
Local time
Today, 06:28
Joined
Apr 9, 2015
Messages
4,337
is [Preferred] as string field or a boolean Y/N field?
 

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
If you want Preferred to contain only 2 values, it should be a Yes/No data field. Sounds like its text.

"N " <> "N"
"N\t" <> "N"
"N\n" <> "N"

You could have a space, a tab or a return character in that string field. Yes/No fields won't accomodate "hidden" characters. Add a calcualted field to that last query:

PLength: Len([Preferred])

Then see what the length is of those seemingly "N" values. Greater than 1 and that means you have a hidden character.
----------------------------------------------------------

I added that calculated field and there are no values greater than 1. So much for the hidden character theory? Thank you for the solution. I don't understand why this is occurring.
 

plog

Banishment Pending
Local time
Today, 05:28
Joined
May 11, 2011
Messages
11,646
Do you have additional criteria in the actual query? Can you post the full actual SQL? Can you post your database?
 

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
No additional Criteria in my query. It's pretty straight forward in my opinion. That's why I don't understand.

I uploaded my criteria as well as the results that are returned. You can see the "N" is still included in the results set.
 

Attachments

  • preference1.JPG
    preference1.JPG
    12.5 KB · Views: 103
  • preference2.JPG
    preference2.JPG
    23.9 KB · Views: 102

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:28
Joined
Feb 19, 2002
Messages
43,266
You may have a corrupted index. Try compact & repair. If that doesn't work, export the table to a csv. Make a copy of the table schema and then delete the table. Compact and repair. Rename the empty table and import the .csv into it.
 

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
You may have a corrupted index. Try compact & repair. If that doesn't work, export the table to a csv. Make a copy of the table schema and then delete the table. Compact and repair. Rename the empty table and import the .csv into it.

It's a table linked via ODBC. Not sure if that makes a difference or not. Also there's approx. 6 million records in it. So exporting to csv doesn't seem too feasible as the cut off is 65,000 for excel. Thanks.
 

Mark_

Longboard on the internet
Local time
Today, 03:28
Joined
Sep 12, 2017
Messages
2,111
It's a table linked via ODBC. Not sure if that makes a difference or not. Also there's approx. 6 million records in it. So exporting to csv doesn't seem too feasible as the cut off is 65,000 for excel. Thanks.

Is this error in EXCEL or ACCESS?

If this is with ACCESS, why would you need to worry about EXCEL?
 

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
Is this error in EXCEL or ACCESS?

If this is with ACCESS, why would you need to worry about EXCEL?

It was suggested that I export the table to a CSV file. The limit is 65,000 records. I have nearly 6 million records in the table.
 

Mark_

Longboard on the internet
Local time
Today, 03:28
Joined
Sep 12, 2017
Messages
2,111
It was suggested that I export the table to a CSV file. The limit is 65,000 records. I have nearly 6 million records in the table.

CSV files themselves have not hard limit on records. CSV is 'Comma separated value'.
 

jdraw

Super Moderator
Staff member
Local time
Today, 06:28
Joined
Jan 23, 2006
Messages
15,379
For clarity, you have an Access table that is linked to ???.

Have you tried working with a smaller sample to get the logic correct and tested? then move to the next issue.

6 million records seems to be a large number of records to be using to track down an issue - have you considered reviewing the data to see what values actually exist in the field Preferred

You could even try where left(preferred,1) ="Y" ---just in case there is an unprintable in the field.
 

DataAnalyst86

Registered User.
Local time
Today, 06:28
Joined
Nov 3, 2017
Messages
13
For clarity, you have an Access table that is linked to ???.

Have you tried working with a smaller sample to get the logic correct and tested? then move to the next issue.

6 million records seems to be a large number of records to be using to track down an issue - have you considered reviewing the data to see what values actually exist in the field Preferred

You could even try where left(preferred,1) ="Y" ---just in case there is an unprintable in the field.

I exported records from the table and imported them into a new table so I would have a smaller sample size. My query logic works when I do that. I guess the issue lies within this large table in which I am linking to.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:28
Joined
Feb 19, 2002
Messages
43,266
Since you never mentioned the ODBC table, I assumed it was ACE or Jet hence my directions to export to .csv so you could fix the index.

We can only help you when we know your environment.

Talk to your DBA and ask him to rebuild the table and indexes for you unless you know how to do it yourself.
 

Users who are viewing this thread

Top Bottom