A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Aceess 2003 Query using NOT operator?



 
 
Thread Tools Display Modes
  #1  
Old July 16th, 2008, 12:28 PM posted to microsoft.public.access.queries
Trevor Aiston
external usenet poster
 
Posts: 43
Default Aceess 2003 Query using NOT operator?

A database I have inherited has field 'Status'. Data is entered in to this
field from a range values in a combo box
"planning/design";"data collection";"data input";"data analysis";"report
preparation";"action plan preparation";"awaiting summary";"project
complete";"project postponed";"project cancelled";"unknown";"long term"

I want to create a query that will return all records 'excluding' "project
complete";"project postponed";"project cancelled" values.

I've played with the NOT operator but think I'm probabably way off mark.

Can anyone suggest a way forward.

Thank you
Trevor
  #2  
Old July 16th, 2008, 12:32 PM posted to microsoft.public.access.queries
Rick Brandt
external usenet poster
 
Posts: 4,354
Default Aceess 2003 Query using NOT operator?

Trevor Aiston wrote:
A database I have inherited has field 'Status'. Data is entered in to
this field from a range values in a combo box
"planning/design";"data collection";"data input";"data
analysis";"report preparation";"action plan preparation";"awaiting
summary";"project complete";"project postponed";"project
cancelled";"unknown";"long term"

I want to create a query that will return all records 'excluding'
"project complete";"project postponed";"project cancelled" values.

I've played with the NOT operator but think I'm probabably way off
mark.

Can anyone suggest a way forward.

Thank you
Trevor


WHERE Status Not In("project complete", "project postponed", "project
cancelled")

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


  #3  
Old July 16th, 2008, 12:35 PM posted to microsoft.public.access.queries
Bob Barrows [MVP]
external usenet poster
 
Posts: 441
Default Aceess 2003 Query using NOT operator?

Trevor Aiston wrote:
A database I have inherited has field 'Status'. Data is entered in to
this field from a range values in a combo box
"planning/design";"data collection";"data input";"data
analysis";"report preparation";"action plan preparation";"awaiting
summary";"project complete";"project postponed";"project
cancelled";"unknown";"long term"

I want to create a query that will return all records 'excluding'
"project complete";"project postponed";"project cancelled" values.

I've played with the NOT operator but think I'm probabably way off
mark.

Can anyone suggest a way forward.

The easiest way is:

WHERE NOT [status] IN ("project complete","project postponed","project
cancelled")

This can be rewritten as:

WHERE [status] "project complete" AND [status] "project postponed" AND
[status] "project cancelled"

I prefer the easy way


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #4  
Old July 16th, 2008, 12:42 PM posted to microsoft.public.access.queries
Bob Barrows [MVP]
external usenet poster
 
Posts: 441
Default Aceess 2003 Query using NOT operator?

Trevor Aiston wrote:
A database I have inherited has field 'Status'. Data is entered in to
this field from a range values in a combo box
"planning/design";"data collection";"data input";"data
analysis";"report preparation";"action plan preparation";"awaiting
summary";"project complete";"project postponed";"project
cancelled";"unknown";"long term"

I want to create a query that will return all records 'excluding'
"project complete";"project postponed";"project cancelled" values.

I've played with the NOT operator but think I'm probabably way off
mark.

Can anyone suggest a way forward.

PS. A more robust, data-driven approach, especially useful when you have to
write multiple queries that need to exclude the same set of status values,
is to create a table, perhaps called "StatusValuesToExclude", enter the list
of status values you wish to exclude, and do a left join to it, filtering
out the records where the staus from the "exclude" table is not null. Like
this:

select ...
from tablename as t left join StatusValuesToExclude as e
on t.[status]=e.[status]
where e.[status] is not null

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #5  
Old July 16th, 2008, 12:52 PM posted to microsoft.public.access.queries
Bob Barrows [MVP][_2_]
external usenet poster
 
Posts: 1
Default Aceess 2003 Query using NOT operator?

"Bob Barrows [MVP]" wrote in message
...
Trevor Aiston wrote:
A database I have inherited has field 'Status'. Data is entered in to
this field from a range values in a combo box
"planning/design";"data collection";"data input";"data
analysis";"report preparation";"action plan preparation";"awaiting
summary";"project complete";"project postponed";"project
cancelled";"unknown";"long term"

I want to create a query that will return all records 'excluding'
"project complete";"project postponed";"project cancelled" values.

I've played with the NOT operator but think I'm probabably way off
mark.

Can anyone suggest a way forward.

PS. A more robust, data-driven approach, especially useful when you have
to write multiple queries that need to exclude the same set of status
values, is to create a table, perhaps called "StatusValuesToExclude",
enter the list of status values you wish to exclude, and do a left join to
it, filtering out the records where the staus from the "exclude" table is
not null. Like this:

select ...
from tablename as t left join StatusValuesToExclude as e
on t.[status]=e.[status]
where e.[status] is not null

Sigh ... I was in too much of a rush. This of course, is backwards. To
exclude the statuses in StatusValuesToExclude you want to only include the
results where e.[status] contains null:

.... where e.[status] is null



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.