PC Review


Reply
Thread Tools Rate Thread

criteria with null value

 
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      7th Nov 2007
Hi,

I am running this SQL to find the price of an item:

SELECT PARTS.UNITPRICE, PARTS.ITEMDESC, PARTS.WIDTH, PARTS.LENGTH,
PARTS.LHEIGHT
FROM PARTS
WHERE (((PARTS.ITEMDESC)=forms!form1.descrip) And
((PARTS.WIDTH)=forms!form1.text2) And ((PARTS.LENGTH)=forms!form1.text4) And
((PARTS.LHEIGHT)=forms!form1.text6));

The problem is, if any of these items are null - the query shows no records.
How can I conditionally check and ignore null values?

Thanks in advance,

Bonnie

 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      8th Nov 2007
On Wed, 7 Nov 2007 14:08:00 -0800, Bonnie <(E-Mail Removed)>
wrote:

>The problem is, if any of these items are null - the query shows no records.
> How can I conditionally check and ignore null values?


Just do so:

SELECT PARTS.UNITPRICE, PARTS.ITEMDESC, PARTS.WIDTH, PARTS.LENGTH,
PARTS.LHEIGHT
FROM PARTS
WHERE
(((PARTS.ITEMDESC)=[forms]![form1]![descrip] OR [forms]![form1]![descrip] IS
NULL)
And
((PARTS.WIDTH)=[forms]![form1]![text2] OR [forms]![form1]![text2] IS NULL)
And
((PARTS.LENGTH)=[forms]![form1]![text4] OR [forms]![form1]![text4] IS NULL)
And
((PARTS.LHEIGHT)=[forms]![form1]![text6] OR [forms]![form1]![text6] IS NULL));

Try to avoid going back to the query grid after pasting the SQL - it will add
all four forms references as calculated fields and make an absolute hash of
the display. Just save the SQL. Also note that ! is a better delimiter for
forms references, and that the square brackets are recommended.

Note also that running the query without filling in any of the textboxes will
return all records. This may be what you want...

John W. Vinson [MVP]


 
Reply With Quote
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      8th Nov 2007
Hi John,

Actually I want to pull up just the records that meet the criteria and
ignore null values. What my SQL code did was pull up nothing if one of the
fields was blank - I want it to ignore a field if it is blank.

Thanks

"John W. Vinson" wrote:

> On Wed, 7 Nov 2007 14:08:00 -0800, Bonnie <(E-Mail Removed)>
> wrote:
>
> >The problem is, if any of these items are null - the query shows no records.
> > How can I conditionally check and ignore null values?

>
> Just do so:
>
> SELECT PARTS.UNITPRICE, PARTS.ITEMDESC, PARTS.WIDTH, PARTS.LENGTH,
> PARTS.LHEIGHT
> FROM PARTS
> WHERE
> (((PARTS.ITEMDESC)=[forms]![form1]![descrip] OR [forms]![form1]![descrip] IS
> NULL)
> And
> ((PARTS.WIDTH)=[forms]![form1]![text2] OR [forms]![form1]![text2] IS NULL)
> And
> ((PARTS.LENGTH)=[forms]![form1]![text4] OR [forms]![form1]![text4] IS NULL)
> And
> ((PARTS.LHEIGHT)=[forms]![form1]![text6] OR [forms]![form1]![text6] IS NULL));
>
> Try to avoid going back to the query grid after pasting the SQL - it will add
> all four forms references as calculated fields and make an absolute hash of
> the display. Just save the SQL. Also note that ! is a better delimiter for
> forms references, and that the square brackets are recommended.
>
> Note also that running the query without filling in any of the textboxes will
> return all records. This may be what you want...
>
> John W. Vinson [MVP]
>
>
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      8th Nov 2007
On Wed, 7 Nov 2007 16:54:01 -0800, Bonnie <(E-Mail Removed)>
wrote:

>Hi John,
>
>Actually I want to pull up just the records that meet the criteria and
>ignore null values. What my SQL code did was pull up nothing if one of the
>fields was blank - I want it to ignore a field if it is blank.


Eh?

So you want a criterion of 123 to pull up all records where the field contains
123, and also all records where the field is NULL? That seems VERY odd. To do
so, though, just add

OR IS NULL

after the form reference:

((PARTS.WIDTH)=[forms]![form1]![text2] OR IS NULL)

Or do you want to ignore the *criterion* if the criterion is blank? My query
will do exactly that.

John W. Vinson [MVP]
 
Reply With Quote
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      8th Nov 2007
Sorry John, I'm having trouble articulating this. I want to pull up the
unitprice from a record with (width=123 or width is null) and (length=345 or
length is null) and (height=567 or height is null). Some items don't use all
of the size descriptors so those size descriptors will be null in those
records.

Does that make sense?

Thanks again.

Bonnie

"John W. Vinson" wrote:

> On Wed, 7 Nov 2007 16:54:01 -0800, Bonnie <(E-Mail Removed)>
> wrote:
>
> >Hi John,
> >
> >Actually I want to pull up just the records that meet the criteria and
> >ignore null values. What my SQL code did was pull up nothing if one of the
> >fields was blank - I want it to ignore a field if it is blank.

>
> Eh?
>
> So you want a criterion of 123 to pull up all records where the field contains
> 123, and also all records where the field is NULL? That seems VERY odd. To do
> so, though, just add
>
> OR IS NULL
>
> after the form reference:
>
> ((PARTS.WIDTH)=[forms]![form1]![text2] OR IS NULL)
>
> Or do you want to ignore the *criterion* if the criterion is blank? My query
> will do exactly that.
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      8th Nov 2007
On Thu, 8 Nov 2007 04:05:00 -0800, Bonnie <(E-Mail Removed)>
wrote:

>Sorry John, I'm having trouble articulating this. I want to pull up the
>unitprice from a record with (width=123 or width is null) and (length=345 or
>length is null) and (height=567 or height is null). Some items don't use all
>of the size descriptors so those size descriptors will be null in those
>records.
>
>Does that make sense?


Ok, the OR IS NULL criterion on each field should work then.

John W. Vinson [MVP]
 
Reply With Quote
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      8th Nov 2007
Yup it did. Thank you sir.

"John W. Vinson" wrote:

> On Thu, 8 Nov 2007 04:05:00 -0800, Bonnie <(E-Mail Removed)>
> wrote:
>
> >Sorry John, I'm having trouble articulating this. I want to pull up the
> >unitprice from a record with (width=123 or width is null) and (length=345 or
> >length is null) and (height=567 or height is null). Some items don't use all
> >of the size descriptors so those size descriptors will be null in those
> >records.
> >
> >Does that make sense?

>
> Ok, the OR IS NULL criterion on each field should work then.
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: criteria = null Nurse Nancy Microsoft Access 6 5th Aug 2009 10:17 PM
QUERY criteria dependent on Is null do A, not is null do B BlueWolverine Microsoft Access Queries 6 13th Jun 2008 02:23 PM
null data not showing up if "is null" query criteria tcek Microsoft Access Queries 6 14th Dec 2007 06:28 PM
Is Null and Is Not Null for criteria =?Utf-8?B?VGltVA==?= Microsoft Access Queries 1 24th Jan 2006 03:08 PM
Criteria to Display All Records Null and Is Not Null =?Utf-8?B?Sm9obkx1dGU=?= Microsoft Access Reports 3 17th Feb 2005 02:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.