Ver Mensaje Individual
  #3  
Antiguo 03-12-2012
ritamarkarla ritamarkarla is offline
Miembro
 
Registrado: sep 2010
Posts: 19
Reputación: 0
ritamarkarla Va por buen camino
codigo

aqui esta el codigo

Código Delphi [-]
      ZQueryEmpresas.Close;
      ZQueryEmpresas.SQL.Clear;
      filtro := 'WHERE ';
      {filtrar por palabras claves}
      if palabras_claves.Text <> EmptyStr
        then
          filtro := filtro + '(palabras_claves like ' + QuotedStr('%' + palabras_claves.Text + '%') + ') and ';
      {comunidad}
      if comunidad.KeyValue <> -1
        then
          if not ZTableComunidad.IsEmpty then
          filtro := filtro + '(empresas.id_comunidad = ' + IntToStr(comunidad.KeyValue) + ') and ';
      {provincia}
      if provincia.KeyValue <> -1
        then
          if not ZTableProvincia.IsEmpty then
          filtro := filtro + '(empresas.id_provincia = ' + IntToStr(provincia.KeyValue) + ') and ';
      {comarca}
      if comarca.KeyValue <> -1
        then
          if not ZTableComarca.IsEmpty then
          filtro := filtro + '(empresas.id_comarca = ' + IntToStr(comarca.KeyValue) + ') and ';
      {ayuntamiento}
      if ayuntamiento.KeyValue <> -1
        then
          if not ZTableAyuntamiento.IsEmpty then
          filtro := filtro + '(empresas.id_ayuntamiento = ' + IntToStr(ayuntamiento.KeyValue) + ') and ';
      {Nombre}
      filtro := filtro + '(nombre LIKE ' + QuotedStr('%' + nombre.Text + '%') + ') or (nombre IS NULL)';
      consulta := 'SELECT empresas.nombre, empresas.forma_juridica, empresas.palabras_claves, empresas.direccion, empresas.codigo_postal, ' + 
'empresas.telefono_1, empresas.telefono_2, empresas.web, empresas.email_1, empresas.email_2, empresas.comentarios, empresas.id, 
comunidad.comunidad, provincia.provincia, comarca.comarca, ayuntamiento.ayuntamiento ' +
                  'FROM (((empresas LEFT JOIN comunidad ON empresas.id_comunidad = comunidad.id) LEFT JOIN provincia ON 
empresas.id_provincia = provincia.id) ' + 'LEFT JOIN comarca ON empresas.id_comarca = comarca.id) LEFT JOIN ayuntamiento ON empresas.id_ayuntamiento = ayuntamiento.id ' +
                  filtro +
                  ' ORDER BY empresas.nombre, comunidad.comunidad, provincia.provincia, comarca.comarca, ayuntamiento.ayuntamiento';
      ZQueryEmpresas.SQL.Add(consulta);
      ZQueryEmpresas.Open;
ZQueryEmpresas.First;

Última edición por Casimiro Noteví fecha: 03-12-2012 a las 16:55:50.
Responder Con Cita