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  

WHERE help needed



 
 
Thread Tools Display Modes
  #1  
Old February 27th, 2007, 03:13 AM posted to microsoft.public.access.queries
Sophie
external usenet poster
 
Posts: 77
Default WHERE help needed

I have SQL that works fine, but I have a question about the WHERE conditions

SELECT ......
FROM ........
WHERE (((K.HardwareClass)=[Forms]![frmHardware].[cbxHClass])
AND ((K.HardwareType)=[Forms]![frmHardware].[cbxHType]));

If both cbxHClass and cbxHType have values, then the query works as planned.
However, I would like it to work even if one of the cbx's is empty, in which
case only one WHERE clause would apply and I have to 'lose' the AND. If both
cbxs are empty, there would be no WHERE at all. Can this be done? (For what
its worth, cbxHClass has numerical values, while cbxHType has literal values.

--
Thanks
Sophie
  #2  
Old February 27th, 2007, 03:22 AM posted to microsoft.public.access.queries
Rick Brandt
external usenet poster
 
Posts: 4,354
Default WHERE help needed

Sophie wrote:
I have SQL that works fine, but I have a question about the WHERE
conditions

SELECT ......
FROM ........
WHERE (((K.HardwareClass)=[Forms]![frmHardware].[cbxHClass])
AND ((K.HardwareType)=[Forms]![frmHardware].[cbxHType]));

If both cbxHClass and cbxHType have values, then the query works as
planned. However, I would like it to work even if one of the cbx's is
empty, in which case only one WHERE clause would apply and I have to
'lose' the AND. If both cbxs are empty, there would be no WHERE at
all. Can this be done? (For what its worth, cbxHClass has numerical
values, while cbxHType has literal values.


SELECT ......
FROM ........
WHERE (K.HardwareClass = [Forms]![frmHardware].[cbxHClass]
OR [Forms]![frmHardware].[cbxHClass] Is Null)
AND (K.HardwareType = [Forms]![frmHardware].[cbxHType]
OR [Forms]![frmHardware].[cbxHType] Is Null);

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


 




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:36 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.