WHERE help needed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Sophie said:
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);
 
Back
Top