Tema: funcion
Ver Mensaje Individual
  #2  
Antiguo 06-10-2003
__cadetill __cadetill is offline
Miembro
 
Registrado: may 2003
Posts: 3.387
Reputación: 25
__cadetill Va por buen camino
debes de crear la sentencia SQL dinámicamente. No obstante, también deberás de pasar por parámetrolos valores a buscar

La función podría ser algo así (no está probada pero sí que compila)

Código:
function TForm1.Existe(Tabla : string; Campos, Valores : TStrings) : boolean;
var
   sql : string;
   i : integer;
   Q : TQuery;
begin
   sql := 'select * from ' + Tabla;
   if Campos.Count <> 0 then
      sql := sql + ' where ';
   for i := 0 to Campos.Count - 1 do
   begin
      if i = Campos.Count - 1 then
         sql := sql + Campos[i] + ' = ' + Valores[i]
      else
         sql := sql + Campos[i] + ' = ' + Valores[i] + ' and ';
   end;

   Q := TQuery.Create(Self);
   Q.DatabaseName := 'MyDataBasename';
   Q.SQL.Text := sql;
   try
      try
         Q.Open;
         if Q.IsEmpty then Result := false
         else Result := true;
      finally
         FreeAndNil(Q);
      end;
   except
      Result := false;
   end;
end;
Espero te sirva la idea
Responder Con Cita