Query: How to smartly code "all others" in query form?

R

Rob Parker

The conventional way would be to use a Not In () contruct in the criterion;
for example:
Not In ("1111", "2222", "3", "4", ...)
[Note: if you need to do this for a field with a numeric datatype, you omit
the delimiting quote marks.]

Thats likely to get a bit unwieldy if you're trying to exclude 23 different
strings.

If you're simply trying to find records which have none of the strings (ie.
are empty), you can use a criterion of Is Null.

Alternatively, if there may be strings other than your pre-defined set of
23, you could create a one-field table of your existing strings (with 23
records), include that in your query with a left (or right, depending on how
you set it up) join to field#1, and add the field from the exclude table to
the query with a criterion of Not Like "*". Your query SQL would be
something like:

SELECT YourTableName.YourFieldName
FROM YourTableName LEFT JOIN TableExcludeName ON YourTableName.YourFieldName
= TableExcludeName.ExcludeString
WHERE TableExcludeName.ExcludeString Not Like "*";

This would allow you to easily change the strings to be excluded, by adding,
editing or removing records from the exclude table.

HTH,

Rob
 
E

EagleOne

Excellent ideas! Thanks

Rob Parker said:
The conventional way would be to use a Not In () contruct in the criterion;
for example:
Not In ("1111", "2222", "3", "4", ...)
[Note: if you need to do this for a field with a numeric datatype, you omit
the delimiting quote marks.]

Thats likely to get a bit unwieldy if you're trying to exclude 23 different
strings.

If you're simply trying to find records which have none of the strings (ie.
are empty), you can use a criterion of Is Null.

Alternatively, if there may be strings other than your pre-defined set of
23, you could create a one-field table of your existing strings (with 23
records), include that in your query with a left (or right, depending on how
you set it up) join to field#1, and add the field from the exclude table to
the query with a criterion of Not Like "*". Your query SQL would be
something like:

SELECT YourTableName.YourFieldName
FROM YourTableName LEFT JOIN TableExcludeName ON YourTableName.YourFieldName
= TableExcludeName.ExcludeString
WHERE TableExcludeName.ExcludeString Not Like "*";

This would allow you to easily change the strings to be excluded, by adding,
editing or removing records from the exclude table.

HTH,

Rob

2003

Assume field#1 contains:

1111
2222
3333
1
2
3
4
5
6
.
.
.
100

In a Query form, it is easy to select "1111" or "2222" or "3333" etc.
in my situation, I have 23 5-character strings. No problem!

But, in the 24th option, I would like to say "All others"

How best enter "NOT" "1111" or "2222" or "3333" etc. in a Query
form? Better ideas?

TIA

EagleOne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top