Criando filtro ou consulta Delphi Access

Delphi

C#

Banco de Dados

ADO

C++

02/02/2020

Caros, boa noite !

Gostaria de compartilha uma duvida com os amigos, e se puder me ajudar, agradeço desde já !
tenho sistema de cadastro com banco access , em meu sistema tenho uma consulta por apartamento, EX: ( 010 ), onde me retorna todos os visitantes deste apartamentos, porem me traz tudo do apartamento (010)
EX:
Pesquisar apartamento : 010, " todos os visitantes do apartamento 010 "
/// código ///
DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+'''');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;

Nome Data
visitante1 - 01/01/2020 - 10h00
visitante1 - 02/01/2020 - 14h00
visitante1 - 03/01/2020 - 12h00
visitante2 - 01/01/2020 - 5h00
visitante2 - 02/01/2020 - 10h00
visitante2 - 03/01/2020 - 1h00
visitante3 - 01/01/2020 - 10h00
visitante3 - 02/01/2020 - 17h00
visitante3 - 03/01/2020 - 18h00

gostaria da ajuda dos amigos para fazer esta consulta com base no apartamento e na data.
EX:
Pesquisar apartamento : 010 Data: 02/01/2020 , " todos os visitantes do apartamento 010, que visitaram no dia 02/01/2020 das 00h00 ate as 23h59"
Nome Data
visitante1 - 02/01/2020 - 14h00
visitante2 - 02/01/2020 - 10h00
visitante3 - 02/01/2020 - 17h00

/// componentes do sistema ///

º Delphi Rad Studio Xe8
º Banco Access 2013
º Nome banco: banco
º Nome da tabela: clientes
º Campo: Nome
º Campo: Data
º ADOConnection: ADOBANCO
º Data module: DM
º ADOQuery: ADOQCAD
º Código Consulta:

DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+'''');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;

desde já agradeço !!!
Natanael Oliveira

Natanael Oliveira

Curtidas 0

Respostas

Gxf

Gxf

02/02/2020


DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+''' and data >= '''+EditDtIni.Text+''' and data <= '''+EditDtFim.Text+''' ');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;
GOSTEI 0
Anderson Gonçalves

Anderson Gonçalves

02/02/2020

Fala boy,

Faça o seguinte.

Levando em consideração que você tem um campo "APARTAMENTO" e outro "HORA DE VISITA" denominados (Apartamento) e (HoraVisita).

SQL

Select * from Cliente
where Apartamento = :apartamento and HoraVisita between :inicio and :fim

ai você passa os parametros do apartamento depois a hora início e hora final do intervalo.

Abraço

Qualquer ajuda a mais me chame.

Skype: anderson@case13.com.br
GOSTEI 0
Natanael Oliveira

Natanael Oliveira

02/02/2020


DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+''' and data >= '''+EditDtIni.Text+''' and data <= '''+EditDtFim.Text+''' ');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;



Olá bom dia !


usando o código acima no botão pesquisar apresenta o seguinte erro ! :


Undeclared identifier ' EditDtIni ' at line 1186
Undeclared identifier ' Text' at line 1186
Undeclared identifier ' EditDtFim' at line 1186
Undeclared identifier ' Text' at line 1186



desde já agradeço !!!

GOSTEI 0
Natanael Oliveira

Natanael Oliveira

02/02/2020

Fala boy,

Faça o seguinte.

Levando em consideração que você tem um campo "APARTAMENTO" e outro "HORA DE VISITA" denominados (Apartamento) e (HoraVisita).

SQL

Select * from Cliente
where Apartamento = :apartamento and HoraVisita between :inicio and :fim

ai você passa os parametros do apartamento depois a hora início e hora final do intervalo.

Abraço

Qualquer ajuda a mais me chame.

Skype: anderson@case13.com.br


Ola Bom dia !

poderia implementar meu código com seu exemplo !!


DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+'''');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;


desde já agradeço !
GOSTEI 0
Gxf

Gxf

02/02/2020


DM.ADOQCAD.Close;
DM.ADOQCAD.SQL.Clear;
DM.ADOQCAD.SQL.Add('Select*from clientes where apartamento = '''+Edit3.Text+''' and data >= '''+EditDtIni.Text+''' and data <= '''+EditDtFim.Text+''' ');
DM.ADOQCAD.SQL.Add('Order By nome');
DM.ADOQCAD.Open;



Olá bom dia !


usando o código acima no botão pesquisar apresenta o seguinte erro ! :


Undeclared identifier ' EditDtIni ' at line 1186
Undeclared identifier ' Text' at line 1186
Undeclared identifier ' EditDtFim' at line 1186
Undeclared identifier ' Text' at line 1186



desde já agradeço !!!



No caso de edtIni e edtFim usei como exemplo para simular o edit de data inicial e tbm o edit de data final. Vc teria que analisar e implementar de acordo com seus campos.

Abs!
GOSTEI 0
POSTAR