como consultar em sql......

Delphi

10/03/2004

como eu faço para consultar, por exemplo, todos os clientes que não compraram NADA NOS ÙLTIMOS SEIS MESES. EM SQL


Fableso

Fableso

Curtidas 0

Respostas

Kyonak

Kyonak

10/03/2004

se você não falar como está relacionada suas tabelas e quais são as tabelas eh impossível responder sua pergunta neh???


GOSTEI 0
Skaarj

Skaarj

10/03/2004

O help do delphi traz algo nesse sentido, mas nao consegui montar um exemplo :oops: :
Properties are useful for manipulating components, especially at design time. But sometimes there are types of manipulations that are so common or natural, often involving more than one property, that it makes sense to provide methods to handle them. One example of such a natural manipulation is a ?next month? feature for a calendar. Handling the wrapping around of months and incrementing of years is simple, but very convenient for the developer using the component. The only drawback to encapsulating common manipulations into methods is that methods are only available at runtime. However, such manipulations are generally only cumbersome when performed repeatedly, and that is fairly rare at design time. For the calendar, add the following four methods for next and previous month and year. Each of these methods uses the IncMonth function in a slightly different manner to increment or decrement CalendarDate, by increments of a month or a year. After incrementing or decrementing CalendarDate, decode the date value to fill the Year, Month, and Day properties with corresponding new values.

procedure TCalendar.NextMonth;

begin
  DecodeDate(IncMonth(CalendarDate, 1), Year, Month, Day);
end;

procedure TCalendar.PrevMonth;

begin
  DecodeDate(IncMonth(CalendarDate, -1), Year, Month, Day);
end;

procedure TCalendar.NextYear;

begin
  DecodeDate(IncMonth(CalendarDate, 12), Year, Month, Day);
end;

procedure TCalendar.PrevYear;

begin
  DecodeDate(CalendarDate, -12), Year, Month, Day);
end;

Be sure to add the declarations of the new methods to the class declaration. Now when you create an application that uses the calendar component, you can easily implement browsing through months or years.



GOSTEI 0
Ossian

Ossian

10/03/2004

Calcule a difereca da data de hoje menos seis meses pra vc ter a consultra entre datas. Vc pode fazer isso pelo delphi ou por um comado sql com o banco de dados, no caso do interbase tem como fazer isso.

Select (os campos vc quer q retorne)
from (as tabelas q vc vai cosultar)
where (Data >= DataDif)

Sendo a data um campo da sua base de dados e datadif é aquela data q vc calculo a seis meses atraz



acho q é mais ou menos isso q vc ta queredo...


GOSTEI 0
Skaarj

Skaarj

10/03/2004

As vzs fechamos os olhos para a simplicidade e so arrumamos para a cabeça.. bom.. 6 meses nao é igual a 180 dias?
Tenta assim:
var
  d:TdateTime;
begin
  d:=date;
  d:=d-180;
  with query1 do
  begin
    close;
    sql.text:=select * from tabela where data >= :dataInf and data <= :datasup´;
    parambyname(´dataInf´).asdatetime:=d;
    parambyname(´datasup´).asdatetime:=date;
    open;
  end;
end;

Ou seja subtraimos os dias correspondentes da data atual e colocamos na var [i:258a4c4427]d[/i:258a4c4427] que sera o piso, e passamos a data atual como teto.
Boa sorte


GOSTEI 0
POSTAR