Fórum Sql.. selecinar atraves de intervalo de dadas? #287601
11/07/2005
0
Obrigado
Ant.neto
Curtir tópico
+ 0Posts
11/07/2005
Ericksasse
Gostei + 0
11/07/2005
Ericksasse
SELECT * FROM TABELA WHERE (DATA >= :PINICIO OR :PINICIO IS NULL) AND (DATA <= :PFIM OR :PFIM IS NULL)
Gostei + 0
12/07/2005
Ant.neto
SELECT * FROM TABELA WHERE (DATA >= :PINICIO OR :PINICIO IS NULL) AND (DATA <= :PFIM OR :PFIM IS NULL)
valeu pela a dica mas esta opção tentei incrementar mas não deu certo.. o sistema travava... tentei usar a sua primeira dica passando o sql em runtime.. Como é a primeira vez que faço.. o sistemas travou tambem...
tem como vc. dar uma olhada neste códigos aí pra ver se existe alguma coisa certa!!
Meu sql normal. sem passar o sql em runtime.
SELECT CodCliente, Nome, Categoria, DDD, TelPrinc, TelLocal, Contato, Pessoa, E_Mail_Princ, Data_cad
FROM ´TbNome.DB´ Tbnome
Where Upper(Tbnome.Nome) Like Upper(:VarNome) and
Tbnome.Data_cad between :VarDataI and :VarDataF and
Upper(Tbnome.Contato) Like Upper(:VarContato)
Order by Tbnome.Nome
Agora passando em runtime que deu pau... (travou)
With QryPesq do Begin close; Sql.clear; Sql.Add(´SELECT CodCliente, Nome, Categoria, DDD, TelPrinc, TelLocal, Contato, Pessoa, E_Mail_Princ, Data_cad FROM "TbNome.DB" Tbnome Where Upper(Tbnome.Nome) Like Upper(:VarNome)´); ParamByName(´VarNome´).AsString:=´¬´+BFSEdit1.text+´¬´; Prepare; Open; end; // QryPesq.ParamByName(´VarNome´).AsString:=´¬´+BFSEdit1.text+´¬´;
tem alguma coisa certa neste código aí de cima?? Valew + 1 vez..
Gostei + 0
12/07/2005
Macaquito86
´select bla bla bla where data between lala and lele ´
Gostei + 0
12/07/2005
Rjun
SQL
SELECT CodCliente, Nome, Categoria, DDD, TelPrinc, TelLocal, Contato, Pessoa, E_Mail_Princ, Data_cad FROM "TbNome.DB" Tbnome
No seu código, faça algo parecido com o código abaixo:
procedure SQLFiltro; var WhereData, WhereSemData: string; begin WhereData := ´Where Upper(Tbnome.Nome) Like Upper(:VarNome) and Tbnome.Data_cad between :VarDataI and :VarDataF and Upper(Tbnome.Contato) Like Upper(:VarContato) Order by Tbnome.Nome ´; WhereSemData := ´Where Upper(Tbnome.Nome) Like Upper(:VarNome) and Upper(Tbnome.Contato) Like Upper(:VarContato) Order by Tbnome.Nome ´; // Verifica se datas são vazias if (edtData1.Text = ´´ or edtData2.Text = ´´) then Query1.SQL.Add(WhereSemData) else begin Query1.SQL.Add(WhereData); Query1.ParambyName(´VarDataI´).Value := StrToDate(edtData1.Text); Query1.ParamByName(´VarDataF´).Value := StrToDate(edtData2.Text); end; try Query1.Open; // Coloque o que você quer fazer com o resultado da query finally Query1.Close; end; end;
Gostei + 0
12/07/2005
Ant.neto
Gostei + 0
12/07/2005
Rjun
Gostei + 0
12/07/2005
Ant.neto
Não deu cara, usei sua instrução mas o sistema trava.... não executa a qry... so roda se eu colocar o sql na prória sql... tá fd resolver isso... mas valeu!!
Gostei + 0
12/07/2005
Rjun
Gostei + 0
12/07/2005
Ant.neto
Paradox - Tbnome.DB (nome da tabele)..
Gostei + 0
13/07/2005
Rjun
Gostei + 0
13/07/2005
Belo
procedure TForm1.Button1Click(Sender: TObject);
begin
with QryPesq do
begin
Close;
SQL.Clear;
SQL.Add(´SELECT * FROM TbNome´);
SQL.Add(´WHERE UPPER(Nome) LIKE:Nome´);
QryPesq.Params[0].AsString := UpperCase(BFSEdit1.Text) + ´¬´;
ExecSQL;
Open;
end;
end;
Esse exemplo é para a pesquisa do campo NOME.
No caso do campo do tipo data, existe várias formas de se fazer, uma delas é convertendo no proprio SQL usando a função CAST, veja:
procedure TForm1.Button1Click(Sender: TObject);
begin
with QryPesq do
begin
Close;
SQL.Clear;
SQL.Add(´SELECT * FROM TbNome´);
SQL.Add(´WHERE WHERE SUBSTRING(CAST(CAST(Data_cad AS DATE) AS CHAR(10)) FROM 1 FOR 10) LIKE:Data_cad´);
QryPesq.Params[0].AsString := BFSEdit1.Text + ´¬´;
ExecSQL;
Open;
end;
end;
Gostei + 0
15/07/2005
Ant.neto
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)