Parameters - return all records when null

G

Gary B

Following is a really cool query I found that allows the passing of a
parameter, and if it is null, it returns all the records. I can not figure
out how to do the same thing when passing more than one parameter (against
different fields).

SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate,
Orders.ShipCountry
FROM Orders
WHERE ((([Enter the country: Example: 'USA']) Is Null)) OR
(((Orders.ShipCountry)=[Enter the country: Example: 'USA']) AND (([Enter the
country: Example: 'USA']) Is Not Null));
 
V

Van T. Dinh

Actually, it is NOT cool: there is a redundant criterion in the WHERE
Clause.

The following SQL should work exactly the same:

SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate,
Orders.ShipCountry
FROM Orders
WHERE ((([Enter the country: Example: 'USA']) Is Null))
OR (((Orders.ShipCountry)=[Enter the country: Example: 'USA']));

You can do similarly for criteria on other Fields.
 

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