Subject | Re: MacroSubstitute |
---|---|
Author | stanw1950 |
Post date | 2004-01-27T18:26:11Z |
--- In IBObjects@yahoogroups.com, "nairne_ulisses"
<nairne_ulisses@y...> wrote:
wrong newsgroup. There are no "macro" substitutes, but you can use
parameters. I have tried to translate your sql below. I did it
programatically (Delphi), but it really looks like a select stored
procedure might be more appropriate, considering the sum statement. I
did not use parameters because of the way you handled Filial and
Pagas, but parameters may still be a good option. I'm sure this sql
won't give you what you want because the sum will sum up all the
valor_liquido for all the records in the table and be the same for
each data_vcto value. It looks to me like you need to get a good sql
book and study up. The ibobjects site has some recommendations in the
bookshop. Also, at info.borland.com/newsgroups in the Interbase
newgroups there is an sql newsgroup that may be more appropriate to
your question.
if qryDespesasDias.Active then qryDespesasDias.Close;
with qryDespesasDias.SQL do begin
Clear;
Add ('SELECT');
Add(' C.DATA_VCTO,');
Add(' (SELECT SUM(VALOR_LIQUIDO) FROM CONTAS_PAGAR) AS TOTAL');
Add('FROM');
Add(' CONTAS_PAGAR C');
Add('WHERE');
Add( Format('C.DATA_VCTO BETWEEN %d AND %d',
[DATA_INICIAL,DATA_FINAL]));
Add(' AND C.TIPO_DUPLICATA <> ''P''); //note two single quotes
around string
if Trim(Filial) <> '' then
Add(' AND FILIAL = 1'); //assuming filial is an integer
// code for tipo
// code for contas_pagar
if Trim(Pagas) <> '' then
Add(' AND PAGAS= 0'); //assuming pagas is an integer
Add('GROUP BY C.DATA_VCTO');
Add('ORDER BY C.DATA_VCTO');
end;
qryDespesasDias.Open;
..more code..
qryDespesasDias.Close;
Good luck,
Stan
<nairne_ulisses@y...> wrote:
> Hi !!at
>
> I am with a problem. I have substitue my old objects from access
> DataBase ( RXLIB ) by IBObjects but I didn't meet similiar code forYour problem is with sql, and not ibobjects, therefore you are in the
> to do:
>
> E.g.(TRXQuery):
>
> SQL->SELECT C.DATA_VCTO, SUM(C.VALOR_LIQUIDO) AS TOTAL
> FROM
> CONTAS_PAGAR C
> WHERE (C.DATA_VCTO BETWEEN :pDATA_INICIAL AND :pDATA_FINAL)
> AND (C.TIPO_DUPLICATA <> 'P') AND (%mFILIAL) AND (%mTIPO)
> AND (% mCONTAS_PAGAR) AND (%mPAGAS)
> GROUP BY C.DATA_VCTO
> ORDER BY C.DATA_VCTO
>
> With qryDespesasDias Do
> Begin
> Close;
> If Trim(pFilial)<>'' Then
> MacroByName('mFILIAL').AsString := 'Filial = 1'
> Else
> MacroByName('mFILIAL').AsString := '0=0';
>
> .
> .
> .
> If Trim(pPagas)<>'' Then
> MacroByName('mPAGAS').AsString := 'Pagas=0'
> Else
> MacroByName('mPAGAS').AsString := '0=0'
>
> Open;
> End;
>
> Thanks
> Ulisses
wrong newsgroup. There are no "macro" substitutes, but you can use
parameters. I have tried to translate your sql below. I did it
programatically (Delphi), but it really looks like a select stored
procedure might be more appropriate, considering the sum statement. I
did not use parameters because of the way you handled Filial and
Pagas, but parameters may still be a good option. I'm sure this sql
won't give you what you want because the sum will sum up all the
valor_liquido for all the records in the table and be the same for
each data_vcto value. It looks to me like you need to get a good sql
book and study up. The ibobjects site has some recommendations in the
bookshop. Also, at info.borland.com/newsgroups in the Interbase
newgroups there is an sql newsgroup that may be more appropriate to
your question.
if qryDespesasDias.Active then qryDespesasDias.Close;
with qryDespesasDias.SQL do begin
Clear;
Add ('SELECT');
Add(' C.DATA_VCTO,');
Add(' (SELECT SUM(VALOR_LIQUIDO) FROM CONTAS_PAGAR) AS TOTAL');
Add('FROM');
Add(' CONTAS_PAGAR C');
Add('WHERE');
Add( Format('C.DATA_VCTO BETWEEN %d AND %d',
[DATA_INICIAL,DATA_FINAL]));
Add(' AND C.TIPO_DUPLICATA <> ''P''); //note two single quotes
around string
if Trim(Filial) <> '' then
Add(' AND FILIAL = 1'); //assuming filial is an integer
// code for tipo
// code for contas_pagar
if Trim(Pagas) <> '' then
Add(' AND PAGAS= 0'); //assuming pagas is an integer
Add('GROUP BY C.DATA_VCTO');
Add('ORDER BY C.DATA_VCTO');
end;
qryDespesasDias.Open;
..more code..
qryDespesasDias.Close;
Good luck,
Stan