pesquisa em sql
Ola, se alguem puder me ajudar , fiz uma pesquiza em sql , indicando um valor inicial e um final, mas so esta me retornando uma parte dos registros, tipo valor inicial = 3656 e final = 3818, so que aparece so ate 3660, o que esta errado , pois sei que tenho mais registros. vai ai ao exemplo que montei:
with IBQuery1 do
begin
close;
sql.Clear;
sql.add(´select * from ordem_SERVICO where´);
sql.add(´numero >=:dtini and numero<=:dtfim´);
sql.add(´order by numero´);
ParamByName(´dtini´).AsInteger:=strtoint(MaskEdit1.Text);
ParamByName(´dtfim´).AsInteger:=strtoint(MaskEdit2.Text);
open;
if IsEmpty then
begin
Showmessage(´Não existe Registros neste intervalo, tente outra vez´);
close;
end;
Se alguem puder me ajudar?
with IBQuery1 do
begin
close;
sql.Clear;
sql.add(´select * from ordem_SERVICO where´);
sql.add(´numero >=:dtini and numero<=:dtfim´);
sql.add(´order by numero´);
ParamByName(´dtini´).AsInteger:=strtoint(MaskEdit1.Text);
ParamByName(´dtfim´).AsInteger:=strtoint(MaskEdit2.Text);
open;
if IsEmpty then
begin
Showmessage(´Não existe Registros neste intervalo, tente outra vez´);
close;
end;
Se alguem puder me ajudar?
Pattarelli
Curtidas 0
Respostas
Raserafim
01/09/2007
tente fazer com que cada contição fique entre parênteses:
sql.add(´[b:f903b5400e]([/b:f903b5400e]numero >=:dtini[b:f903b5400e])[/b:f903b5400e] and [b:f903b5400e]([/b:f903b5400e]numero<=:dtfim[b:f903b5400e])[/b:f903b5400e]´);
sql.add(´[b:f903b5400e]([/b:f903b5400e]numero >=:dtini[b:f903b5400e])[/b:f903b5400e] and [b:f903b5400e]([/b:f903b5400e]numero<=:dtfim[b:f903b5400e])[/b:f903b5400e]´);
GOSTEI 0
Pattarelli
01/09/2007
Muito obrigado, deu certo...... valew..
GOSTEI 0
Superdelphi
01/09/2007
Caros colegas o between não faz a mesma coisa que o
(numero >=:dtini) and (numero<=:dtfim)
(numero >=:dtini) and (numero<=:dtfim)
GOSTEI 0
Raserafim
01/09/2007
sim são equivalentes.
a sintaxe é a seguinte:
where nomecampo between valor1 and valor2
a sintaxe é a seguinte:
where nomecampo between valor1 and valor2
GOSTEI 0