Fazer um select titulos a vencer deste ano e proximo anos?

Firebird

13/07/2008

Pessoal, como eu faço um select para pegar os titulos a vencer que estão no banco:

Tenho que pegar os meses seguinte e também os anos seguintes em uma soma.

Assim esta pegando a soma dos proximos meses, mais não os que também tem no proximo ano ou anos


select
   coalesce(sum(VL_PARCELA),0) SomaAnt,
   count(*) QuantAnt
from CONTASAPAGAR
where                                     
  extract(month from vencimento) >=
  extract(month from current_date) + 1
and                                       
  extract(year from vencimento) >=
  extract(year from current_date)
and
  liquidado = ´N´



Não posso fazer assim

select coalesce(sum(VL_PARCELA),0) SomaAnt,
count(*) QuantAnt from CONTASAPAGAR       
where                                     
vencimento > current_date                 
and                                       
liquidado = ´´N´´



Pq neste caso pega a soma dos que vencem neste mes também, e preciso que comece a partir do proximo mes, e não estou sabendo montar a select.


Adriano_servitec

Adriano_servitec

Curtidas 0

Respostas

Adriano_servitec

Adriano_servitec

13/07/2008

É assim o esquema?

Não testei ainda direito, mais se não for desta forma, aguem pode me dizer por favor, não pode haver furo nesta soma

Meses anteriores

procedure TfrmCadContasaPagar.somaMesesAnteriores;
var
 TotQuantAtr : integer;
 TotSomaAnt  : Real;
 DataFin : TDateTime;
 vMesAnt : string;
begin
   {:Pega o mes atual e diminuo para o mes anterios}
  DataFin := IncMonth(DATE,-1);
  {:Variavel esta pegando o ultimo dia do mes anterior usando
  o EndOfTheMonth do DateUtils}
  vMesAnt := DateToStr(EndOfTheMonth(DataFin));
  with ibqSomas do
  begin
    Close;
    Sql.Clear;
    Sql.Text := ´ select coalesce(sum(VL_PARCELA),0) SomaAnt,  ´+
                ´ count(*) QuantAnt from CONTASAPAGAR          ´+
                ´ where                                        ´+
                ´ vencimento <= :p_MesAnt                      ´+
                ´ and                                          ´+
                ´ liquidado = ´´N´´                            ´;

    ParamByName(´p_MesAnt´).AsDateTime := StrToDate(vMesAnt);
    Open;
    TotQuantAtr := FieldByName(´QuantAnt´).AsInteger;
    TotSomaAnt  := FieldByName(´SomaAnt´).AsCurrency;
    Label117.Caption   := IntToStr(TotQuantAtr);
    Label118.Caption   := Format(´¬12.2n´,[TotSomaAnt]);
  end;
end;



Proximos meses
procedure TfrmCadContasaPagar.somaProximosMeses;
var
 TotQuantAtr : integer;
 TotSomaAnt  : Real;
 DataIni : TDateTime;
 vProxMes : string;
begin
  {:Pega o mes atual e soma o proximo mes}
  dataIni := IncMonth(DATE,1);
  {:Variavel esta pegando o primeiro dia do proximo mes usando
  o StartOfTheMonth do DateUtils}
  vProxMes := DateToStr(StartOfTheMonth(DataIni));
  with ibqSomas do
  begin
    Close;
    Sql.Clear; 
    Sql.Text := ´ select coalesce(sum(VL_PARCELA),0) SomaAnt,  ´+
                ´ count(*) QuantAnt from CONTASAPAGAR          ´+
                ´ where                                        ´+
                ´ vencimento >= :p_proxMes                     ´+
                ´ and                                          ´+
                ´ liquidado = ´´N´´                            ´;

    ParamByName(´p_proxMes´).AsDateTime := StrToDate(vProxMes);
    Open;
    TotQuantAtr := FieldByName(´QuantAnt´).AsInteger;
    TotSomaAnt  := FieldByName(´SomaAnt´).AsCurrency;
    Label41.Caption   := IntToStr(TotQuantAtr);
    Label42.Caption   := Format(´¬12.2n´,[TotSomaAnt]);   
  end;
end;



GOSTEI 0
POSTAR