--- hermes/lib/Driver/sql.php.orig	2008-03-31 18:52:44.000000000 -0400
+++ hermes/lib/Driver/sql.php	2008-03-31 18:52:21.000000000 -0400
@@ -210,34 +210,34 @@
         $fieldlist = implode(', ', $fieldlist);
         $sql = 'SELECT ' . $fieldlist . ' FROM hermes_timeslices b INNER JOIN hermes_jobtypes j ON b.jobtype_id = j.jobtype_id';
         if (count($filters) > 0) {
-            $sql .= ' WHERE';
+	    $where = '';
             $glue = '';
             foreach ($filters as $field => $filter) {
                 switch ($field) {
                 case 'client':
-                    $sql .= $glue . $this->_equalClause('b.clientjob_id',
+                    $where .= $glue . $this->_equalClause('b.clientjob_id',
                                                         $filter);
                     $glue = ' AND';
                     break;
 
                 case 'jobtype':
-                    $sql .= $glue . $this->_equalClause('b.jobtype_id',
+                    $where .= $glue . $this->_equalClause('b.jobtype_id',
                                                         $filter);
                     $glue = ' AND';
                     break;
 
                 case 'submitted':
-                    $sql .= $glue . ' timeslice_submitted = ' . (int)$filter;
+                    $where .= $glue . ' timeslice_submitted = ' . (int)$filter;
                     $glue = ' AND';
                     break;
 
                 case 'exported':
-                    $sql .= $glue . ' timeslice_exported = ' . (int)$filter;
+                    $where .= $glue . ' timeslice_exported = ' . (int)$filter;
                     $glue = ' AND';
                     break;
 
                 case 'billable':
-                    $sql .= $glue
+                    $where .= $glue
                         . (empty($conf['time']['choose_ifbillable'])
                            ? ' jobtype_billable = '
                            : ' timeslice_isbillable = ')
@@ -246,34 +246,37 @@
                     break;
 
                 case 'start':
-                    $sql .= $glue . ' timeslice_date >= ' . (int)$filter;
+                    $where .= $glue . ' timeslice_date >= ' . (int)$filter;
                     $glue = ' AND';
                     break;
 
                 case 'end':
-                    $sql .= $glue . ' timeslice_date <= ' . (int)$filter;
+                    $where .= $glue . ' timeslice_date <= ' . (int)$filter;
                     $glue = ' AND';
                     break;
 
                 case 'employee':
-                    $sql .= $glue . $this->_equalClause('employee_id',
+                    $where .= $glue . $this->_equalClause('employee_id',
                                                         $filter);
                     $glue = ' AND';
                     break;
 
                 case 'id':
-                    $sql .= $glue . $this->_equalClause('timeslice_id',
+                    $where .= $glue . $this->_equalClause('timeslice_id',
                                                         $filter, false);
                     $glue = ' AND';
                     break;
 
                 case 'costobject':
-                    $sql .= $glue . $this->_equalClause('costobject_id',
+                    $where .= $glue . $this->_equalClause('costobject_id',
                                                         $filter);
                     $glue = ' AND';
                     break;
                 }
             }
+	    if (0 < strlen($where)) {
+	        $sql .= " WHERE $where";
+	    }
         }
 
         $sql .= ' ORDER BY timeslice_date DESC, clientjob_id';