} //end of if statement (!tables.contains(tableName))
                  // alias determination
                  Collection alias = new ArrayList();
                  StringTokenizer aliasCommaTokens = new StringTokenizer(thisRealTable, ",");
                  while(aliasCommaTokens.hasMoreTokens()){
            String aliasRealTable = aliasCommaTokens.nextToken();
            StringTokenizer aliasTokens = new StringTokenizer(aliasRealTable, " ");
            int tokenLen = aliasTokens.countTokens();
            if(tokenLen > 1){
              if(aliasTokens.hasMoreTokens())
              {
                String tempTableName = aliasTokens.nextToken();
                alias.add(aliasTokens.nextToken());
              }//end of if(aliasTokens.hasMoreTokens())
            }
            else{
              if(aliasTokens.hasMoreTokens())
              {
                alias.add(aliasTokens.nextToken());
              }
            }
          }//end of while(aliasCommaTokens.hasMoreTokens())
                  thisRelationship = (String) fieldHashMap.get("RelationshipQuery");
                  if (thisRelationship != null)
                  {
                    StringTokenizer relationshipTokens = new StringTokenizer(thisRelationship, " ");
                    while (relationshipTokens.hasMoreTokens())
                    {
                      String thisToken = relationshipTokens.nextToken();
                      int index = thisToken.indexOf(".");
                      if (index > -1)
                      {
                        String tableName = null;
                        if (thisToken.indexOf("(") == 0) {  // grrrrrrr
                          tableName = thisToken.substring(1, index);
                        } else {
                          tableName = thisToken.substring(0, index);
                        }
                        //Incase if you added the new line to the Query then before
                        //check for the occurance. We will eliminate the new line return character.
                        tableName = tableName.replaceAll("\n","");
                        if ((!allTables.contains(tableName)) && (!alias.contains(tableName)))
                        {
                          allTables.add(tableName);
                        } //end of if statement (!tables.contains(tableName))
                      } //end of if statement (index > -1)
                    } //end of while loop (relationshipTokens.hasMoreTokens())
                  } //end of if statement (thisRelationship != null)
                } //end of if statement (isOnTable.equalsIgnoreCase("N"))
              } //end of if statement (fieldIterator.hasNext())
            } //end of if statement (fieldResults != null)
            if (thisRealTable.length() < 1)
            {
              thisRealTable = thisTable;
            } //end of if statement (thisRealTable.length() < 1)
            // This is the actual interesting part of the WHERE clause
            String valueCondition = (String) this.getConditionString(
              searchCriteria.getValue(), thisField, thisRealTable,
              Integer.parseInt(searchCriteria.getConditionID()));
            // Build the criterion Query
            selectQuery.append("SELECT ");
            selectQuery.append(thisTable);
            selectQuery.append(".");
            selectQuery.append(thisPrimaryKey);
            selectQuery.append(" FROM ");
            Iterator thisTableIterator = allTables.iterator();
            while (thisTableIterator.hasNext())
            {
              String currentTable = (String) thisTableIterator.next();
              selectQuery.append(currentTable);
              if (thisTableIterator.hasNext())
              {
                selectQuery.append(", ");
              } //end of if statement (thisTableIterator.hasNext())
            } //end of while loop (thisTableIterator.hasNext())
            // The actual Question the user is asking about this field:
            StringBuffer fieldCriterion = new StringBuffer();
            //If there is a relationship, this following piece
            //should be setup in the database.
            if (thisRelationship == null || thisRelationship.length() < 1)
            {
              fieldCriterion.append(thisRealTable);
              fieldCriterion.append(".");
            } //end of if statement (thisRelationship == null ...
            fieldCriterion.append(thisField);
            fieldCriterion.append(" ");
            fieldCriterion.append(valueCondition);
            // the following things don't have "record" rights applied
            // they can be skipped and just do this thing.
            if (thisRealTable.equalsIgnoreCase("methodofcontact")
                || thisRealTable.equalsIgnoreCase("customfield")
                || thisRealTable.equalsIgnoreCase("address")
                || (thisRelationship != null && thisRelationship.length() > 0))
            {
              //This is bad.... bad bad bad, but there isn't an easier way
              //to do this.
              selectQuery.append(" WHERE ");
              if (thisRelationship != null && thisRelationship.length() > 0)
              {
                selectQuery.append(thisRelationship);
                selectQuery.append(" AND ");
              } //end of if statement (thisRelationship != null ...
              selectQuery.append(fieldCriterion);
            } //end of if statement (thisTable.equals("methodofcontact"))...
            else
            {
              // Gotta do some record rights crap.
              selectQuery.append(this.getRecordPermissionQuery(individualID,
                thisRealTable, thisPrimaryKey, selectQuery, fieldCriterion,
                searchVO.getModuleID(),allTables));
            } //end of else statement (thisTable.equals("methodofcontact"))...
          } // end else for if (searchCriteria.getTableID().equals(CUSTOM_FIELD_TABLEID))
          // built the query now get iterum results.
          cvdal.setSqlQuery(selectQuery.toString());
          Collection searchResults = cvdal.executeQuery();
          cvdal.setSqlQueryToNull();
          if (searchResults != null)
          {
            StringBuffer commaDelimitedIDs = new StringBuffer("");
            Iterator resultsIterator = searchResults.iterator();
            while (resultsIterator.hasNext())
            {
              HashMap resultsHashMap = (HashMap) resultsIterator.next();
              Number primaryID = (Number) resultsHashMap.get(thisPrimaryKey);
              commaDelimitedIDs.append(primaryID.toString());
              if (resultsIterator.hasNext())
              {
                commaDelimitedIDs.append(", ");
              } //end of if statement (resultsIterator.hasNext())
            } //end of while loop (resultsIterator.hasNext())
            if (commaDelimitedIDs.length() < 1)
            {
              commaDelimitedIDs.append("0");
            } //end of if statement (commaDelimitedIDs.length() < 1)
            // interumResults are now keyed on a unique counter
            interumResults.put(new Integer(searchCriteriaCounter), commaDelimitedIDs.toString());
          } //end of if statement (searchResults != null)
          // whack the tables from this list
          allTables.clear();
          // The guaranteed unique counter is now stored in the collection of searchCriteria
          // which we are working with.
          searchCriteria.setSearchCriteriaID(String.valueOf(searchCriteriaCounter));
          searchCriteriaCounter++;
        } //end of while loop (criteriaIterator.hasNext())
      } //end of if statement (criteriaCollection != null)
      //End Criteria Searches
      // Build the relationship and get out the primary keys we need.
      if (criteriaCollection != null)
      {
        Iterator criteriaIterator = criteriaCollection.iterator();
        while (criteriaIterator.hasNext())
        {
          SearchCriteriaVO searchCriteria = (SearchCriteriaVO) criteriaIterator.next();
          Integer searchCriteriaId = new Integer(searchCriteria.getSearchCriteriaID());
          // See if its worth finding the relationship, etc.  If there is no
          // interum results then there will most definitely be no final results
          String ids = (String)interumResults.get(searchCriteriaId);
          String relationshipQuery = "";
          if (ids != null && ids.length() > 0 && !ids.equals("0")) // oh yeah, and if it equals 0, we can skip it too.
          {
            // if the table for this criteria is not the primary table, then we need to
            // get the relationship query from searchtablerelate, and run a query to
            // reduce back to the primarykey.
            if ((primaryTableID.intValue() != Integer.parseInt(searchCriteria.getTableID()))
                && !(searchCriteria.getTableID().equals(SearchVO.CUSTOM_FIELD_TABLEID)))
            {
              String tableString = "SELECT RelationshipQuery FROM searchtablerelate " +
                  "WHERE (LeftSearchTableID = ? AND RightSearchTableID = ?) " +
                  "OR (LeftSearchTableID = ? AND RightSearchTableID = ?)";
              cvdal.setSqlQuery(tableString);
              cvdal.setInt(1, primaryTableID.intValue());
              cvdal.setInt(2, Integer.parseInt(searchCriteria.getTableID()));
              cvdal.setInt(3, Integer.parseInt(searchCriteria.getTableID()));
              cvdal.setInt(4, primaryTableID.intValue());
              Collection relationCollection = cvdal.executeQuery();
              cvdal.setSqlQueryToNull();
              if (relationCollection != null)
              {
                Iterator relationIterator = relationCollection.iterator();
                if (relationIterator.hasNext())
                {
                  HashMap relationHashMap = (HashMap)relationIterator.next();
                  relationshipQuery = (String)relationHashMap.get("RelationshipQuery");
                  // build up a collection of all the tables referenced in the relationship
                  // query.
                  StringTokenizer relationshipTokens = new StringTokenizer(relationshipQuery, " ");
                  while (relationshipTokens.hasMoreTokens())
                  {
                    String thisToken = relationshipTokens.nextToken();
                    int index = thisToken.indexOf(".");
                    if (index > -1)
                    {
                      String tableName = thisToken.substring(0, index);
                      if (!allTables.contains(tableName))