Fórum Instrução SQL entre datas #559377
18/07/2016
0
procedure TFrmProntuario.BitBtn7Click(Sender: TObject);
begin
If DateTimePicker2.Date < DateTimePicker1.Date Then begin
ShowMessage('Data inicial maior que a final!');
DateTimePicker2.Date := DateTimePicker1.Date;
end else
begin
With Tabelas do
Begin
QyPesquisa.Close;
QyPesquisa.SQL.Clear;
QyPesquisa.SQL.Add('select count(ITEM) as TOTAL from GERAL');
QyPesquisa.SQL.Add('where entrada between :DataIni and :DataFim');
QyPesquisa.SQL.Add('GROUP BY ITEM');
QyPesquisa.ParamByName('DataIni').AsDate := DateTimePicker1.Date;
QyPesquisa.ParamByName('DataFim').AsDate := DateTimePicker2.Date;
QyPesquisa.Open;
RptListageral:=TRptListageral.Create(Application);
RptListageral.QuickRep1.Preview;
RptListageral.Free;
end;
end;
end;
Claudecir Joahsenn
Curtir tópico
+ 1Posts
19/07/2016
Roberto Wutke
QyPesquisa.SQL.Add('select count(ITEM) as TOTAL from GERAL');
QyPesquisa.SQL.Add('where entrada between :DataIni and :DataFim');
QyPesquisa.SQL.Add('GROUP BY ITEM');
sempre que vc faz o ADd ele vai substituindo o que estava la anteriormente.... vc pode fazer de 2 formas
criar uma variavel Comando : String e ela receber o comando, ficando assim....
Comando := 'select count(ITEM) as TOTAL from GERAL'
+ 'where entrada between :DataIni and :DataFim'
+ 'GROUP BY ITEM';
QyPesquisa.SQL.Add(Comando);
ou concatenar o comando todo de uma vez na sua query
QyPesquisa.SQL.Add('select count(ITEM) as TOTAL from GERAL'
+ 'where entrada between :DataIni and :DataFim'
+ 'GROUP BY ITEM');
acho quer seria isso mano vei...
Bons codigos
Gostei + 0
19/07/2016
Raylan Zibel
".SQL" é um TStrings, então o ".Add" deve funcionar sem problemas. Seria mais seguro apenas colocar um espaço no inicio ou final de cada linha pra evitar erros caso o banco tente concatenar com a linha anterior.
Talvez o problema esteja aqui.
RptListageral.QuickRep1.Preview; // substituir por ".PreviewModal" RptListageral.Free; // se for um TForm, tente usar um ".Release"
Gostei + 0
19/07/2016
Raylan Zibel
If DateTimePicker2.Date < DateTimePicker1.Date Then
begin
ShowMessage('Data inicial maior que a final!');
DateTimePicker2.Date := DateTimePicker1.Date;
end
else
begin
With Tabelas do
Begin
QyPesquisa.Close;
QyPesquisa.SQL.Clear;
QyPesquisa.SQL.Add('select ITEM, count(ITEM) as TOTAL from GERAL');
QyPesquisa.SQL.Add('where entrada between :DataIni and :DataFim');
QyPesquisa.SQL.Add('GROUP BY ITEM');
QyPesquisa.ParamByName('DataIni').AsDate := DateTimePicker1.Date;
QyPesquisa.ParamByName('DataFim').AsDate := DateTimePicker2.Date;
QyPesquisa.Open;
RptListageral := TRptListageral.Create(Application);
RptListageral.QuickRep1.PreviewModal;
RptListageral.Free;
end;
end;
Gostei + 0
20/07/2016
Claudecir Joahsenn
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)