[Zope-DB] sqlgroup queries

Chad Nantais cnantais@rednaxel.com
Mon, 25 Feb 2002 23:59:52 -0500


I have created a search form where users can enter as much info as they have
to narrow down a search. The variables are: first_name, last_name, city,
province.  The query i am currently using only returns a record when all
fiels are filled in and correctly match the query. However, if some fields
are left blank, I want the query to return results that most closely match
the fields that had values entered. Here's the current code:

## arguments are: first_name, last_name, city, province
SELECT * FROM customer
<dtml-sqlgroup where>
   <dtml-sqltest first_name op=like type=string optional>
   <dtml-and>
   <dtml-sqltest last_name op=like type=string optional>
   <dtml-and>
   <dtml-sqltest city op=like type=string optional>
   <dtml-and>
   <dtml-sqltest province op=like type=string optional>
</dtml-sqlgroup>


Basically, if the form field "city" is left blank, I want it excluded from
the search criteria.

Thanks.