Using parameter in query to specify null/not null records

A

Amy Blankenship

I have this query:

Select Max(SessionID) FROM Session WHERE ObjectID = [Enter CatID] And
LevelID = 2 And [EndTime] Is Null

I want to be able to use a parameter to be able to switch at will from

AND [EndTime] Is Null

to

AND [EndTime] Is NOT Null

Obviously, this is to be able to return values from only closed sessions or
from only open sessions. I haven't encountered this syntax before in my
work with Access, so I am a bit unsure as to how to phrase this.

Does anyone have any ideas?

Thanks;

Amy
 
J

John Spencer

You M_I_G_H_T be able to do that with the following: Enter anything at
all in response to the prompt if you want non-null values

Select Max(SessionID)
FROM Session
WHERE ObjectID = [Enter CatID]
And LevelID = 2
And (([EndTime] Is Null And [Leave Blank for Null] is Null)
OR ([EndTime] is Not Null and [Leave Blank for Null] is Not Null))


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
A

Amy Blankenship

Yes, I wound up doing something similar.

Thanks;

Amy

John Spencer said:
You M_I_G_H_T be able to do that with the following: Enter anything at
all in response to the prompt if you want non-null values

Select Max(SessionID)
FROM Session
WHERE ObjectID = [Enter CatID]
And LevelID = 2
And (([EndTime] Is Null And [Leave Blank for Null] is Null)
OR ([EndTime] is Not Null and [Leave Blank for Null] is Not Null))


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
.

Amy Blankenship said:
I have this query:

Select Max(SessionID) FROM Session WHERE ObjectID = [Enter CatID] And
LevelID = 2 And [EndTime] Is Null

I want to be able to use a parameter to be able to switch at will from

AND [EndTime] Is Null

to

AND [EndTime] Is NOT Null

Obviously, this is to be able to return values from only closed sessions
or from only open sessions. I haven't encountered this syntax before in
my work with Access, so I am a bit unsure as to how to phrase this.

Does anyone have any ideas?

Thanks;

Amy
 

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