code: private Query getQueryBySqlCount(QueryBySQL aQuery)
      {
          String countSql = aQuery.getSql();
  
          int fromPos = countSql.toUpperCase().indexOf(" FROM ");
          if(fromPos >= 0)
          {
              countSql = "select count(*)" + countSql.substring(fromPos);
          }
  
          int orderPos = countSql.toUpperCase().indexOf(" ORDER BY ");
          if(orderPos >= 0)
          {
              countSql = countSql.substring(0, orderPos);
          }
  
          return new QueryBySQL(aQuery.getSearchClass(), countSql);
      }
docs: Create a Count-Query for QueryBySQL
  
  @param aQuery
  @return The count query