Cita:
ya que no comprendo de la funcion MakeSQLstring
|
Hola naty_prog.
Voy a tratar de explicarla documentando el código de la función misma. (Que bién podría haberse llamado
HacerCadenaSQL ![Smilie](http://www.clubdelphi.com/foros/images/smilies/smile.gif)
).
Código Delphi
[-]
function TForm_docente.MakeSQLString: string;
var
TS: TStrings;
i: Integer;
begin
Result:= 'SELECT * FROM DOCENTE '; TS:= TStringList.Create;
try
if ComboBox1.ItemIndex > 0 then TS.Add('TIPODOC = :TIPO');
if Combobox2.ItemIndex > 0 then TS.Add('ID_DOCENTE = :MAT');
if ComboBox3.ItemIndex > 0 then TS.Add('ID_LOCALIDAD =:LOC');
if ComboBox4.ItemIndex > 0 then TS.Add('SEXO = :SEX');
case ComboBox5.ItemIndex of 1: TS.Add('EDAD = :EDA'); 2: TS.Add('EDAD > :EDA'); 3: TS.Add('EDAD < :EDA'); 4: TS.Add('EDAD BETWEEN :EDA AND :EDA2') end;
if TS.Count > 0 then begin
Result:= Result + 'WHERE '; for i:= 0 to TS.Count-1 do
if i < TS.Count-1 then Result:= Result + TS[i] + ' AND ' else
Result:= Result + TS[i]; end;
case ComboBox6.ItemIndex of 1: Result:= Result + ' ORDER BY NOMBRE_APELLIDO ASC'; 2: Result:= Result + ' ORDER BY NOMBRE_APELLIDO DESC' end
finally
TS.Free end;
end;
Si no he sido suficientemente claro, hacemelo saber y gustoso trataré de explicarme de otro modo.
Un saludo.
Edito: Ya me olvidaba de ejemplificar el uso...
Código Delphi
[-]
var
CadenaSQL: string;
begin
CadenaSQL:= MakeSQLString
end;