Hello MVD community. I use the procedure below to generate a report. Works well. I use dtIni and dtFim to put the period in the report title. Is it possible to simplify this comparison (> =, <=) with dates?
Or is there another way to put the query date range in the report header?
procedure frmListVendas_bRelVendas_OnClick (Sender: string; var Cancel: boolean);
//****** alimenta relatório padrão lista de vendas a partir do tablegrid
var
i,c: integer;
s, YY, MM, DD: string;
Y,M,D: Word;
v_dtini, v_dtfim: string;
begin
s := '';
DecodeDate(frmListVendas.dtIni.Date, Y, M, D);
YY := vartostr(Y); MM :=vartostr(M); DD := vartostr(D);
if length(MM) = 1 then MM := '0'+MM; if length(DD) = 1 then DD := '0'+DD;
v_dtini := YY+'-'+MM+'-'+DD; showmessage(v_dtini);
DecodeDate(frmListVendas.dtFim.Date, Y, M, D);
YY := vartostr(Y); MM :=vartostr(M); DD := vartostr(D);
if length(MM) = 1 then MM := '0'+MM; if length(DD) = 1 then DD := '0'+DD;
v_dtfim := YY+'-'+MM+'-'+DD; showmessage(v_dtfim);
frmListVendas.bRelVendas.dbSQL := '';
frmListVendas.bRelVendas.dbSQL := 'SELECT "Vendas"."Nota_Fiscal", "Vendas"."Pedido", '+
' strftime("%d-%m-%Y","Vendas"."Data_Venda") as Data_Venda, '+
' (SELECT strftime("%d-%m-%Y",Min("Vendas"."Data_Venda")) from Vendas where Data_Venda >= '+v_dtini+') as DtIni,'+
' (SELECT strftime("%d-%m-%Y",Max("Vendas"."Data_Venda")) from Vendas where Data_Venda <= '+v_dtfim+') as DtFim,'+
' "Clientes"."Clie_Nome", '+
' "Vendedores"."Vend_Nome", '+
' "Vendas"."Quantidade", '+
' "Vendas"."Valor" '+
'FROM "Vendas" '+
'LEFT OUTER JOIN "Clientes" ON "Vendas"."id_Clientes" = "Clientes"."id" '+
'LEFT OUTER JOIN "Vendedores" ON "Vendas"."id_Vendedores" = "Vendedores"."id" ';
c := frmListVendas.TableGrid_Vendas.RowCount-1;
for i := 0 to c do
begin
s := s + ''+IntToStr(frmListVendas.TableGrid_Vendas.dbIndexToID(i)) + ',';
end;
if s <> '' then
begin
SetLength(s, Length(s)-1);
//showmessage(s);
frmListVendas.bRelVendas.dbSQL := frmListVendas.bRelVendas.dbSQL + ' WHERE Vendas.id IN (' + s +') ORDER BY Data_Venda';
end;
if (frmListVendas.TableGrid_Vendas.RowCount-1) = -1 then cancel := True;
end;