Duvidas Urgentes SQL Consulta
Olá pessoal,
Estou com um probleminha. Estou fazendo um programa de relatório, onde quero que imprima somente titulares que fazem aniversario no seguinte intervalo de datas. Esta dando erro q eu nao sei o q é.
Banco: Cadastro.dbf
Delphi:6.0
Nasc: Campo nascimento
QR_Cad: Query do banco cadastro.
var
d1, d2, d3, m1, m2, m3, a1, a2, a3: word; {(onde d=dia, m=mes, a=ano e 1 = data inicial, 2=data final, 3=data da tabela)}
Begin
If (DtInicial.text = ´ / ´) or (DtFinal.text = ´ / ´) then
ShowMessage(´Informe o período que deseja consultar!´)
else
with QR_Cad do
begin
filtered := true;
decodedate(strtodate(DtInicial.text),a1,m1,d1);
decodedate(strtodate(DtFinal.text),a2,m2,d2);
first;
While not Eof do
Begin
decodedate(QR_Cad.fieldbyname(´NASC´).AsDateTime,a3,m3,d3);
if ((d3>=d1) and (m3>=m1)) and ((d3<=d2) and (m3<=m2)) then
begin
QR_Cad.Close;
QR_Cad.SQL.Clear;
QR_Cad.SQL.Add(´Select * from Cadastro WHERE NASC BETWEEN :DtInicial AND :DtFinal´);
QR_Cad.SQL.Add (´where extract(DAY FROM NASC) >= :Dia1 and extract(month FROM NASC) >= :Mes1 and extract(DAY FROM NASC) <= :Dia2 and extract(month FROM NASC) <=:Mes2´);
QR_Cad.SQL.Add(´order by Nome, NASC´);
QR_Cad.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
QR_Cad.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
QR_Cad.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
QR_Cad.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
QR_Cad.Open;
end;
end;
Acontece a mesma coisa quando tento fazer consulta dos dependentes. E aonde está em vermelho, é o lugar em q eu estou mais enrolada, pois o MSN do titular tem q ser igual ao MSN do dependente
Banco: Depend.dbf
Delphi:6.0
NascD: Campo nascimento
MSN: Matricula do titular
Query_depend: Query do banco cadastro.
var
d1, d2, d3, m1, m2, m3, a1, a2, a3: word; {(onde d=dia, m=mes, a=ano e 1 = data inicial, 2=data final, 3=data da tabela)}
Begin
If (DtInicial.text = ´ / ´) or (DtFinal.text = ´ / ´) then
ShowMessage(´Informe o período que deseja consultar!´)
else
with Query_Depend do
begin
filtered := true;
decodedate(strtodate(DtInicial.text),a1,m1,d1);
decodedate(strtodate(DtFinal.text),a2,m2,d2);
first;
While not Eof do
Begin
decodedate(Query_Depend.fieldbyname(´NASCD´).AsDateTime,a3,m3,d3);
if ((d3>=d1) and (m3>=m1)) and ((d3<=d2) and (m3<=m2)) then
Query_Depend.Close;
Query_Depend.SQL.Clear;
Query_Depend.SQL.Add(´Select * from Depend, Cadastro WHERE NASCD BETWEEN :DtInicial AND :DtFinal´);
[color=red:39e8f5997e]Query_Depend.SQL.Add(´and Cadastro.MS = Depend.MS´);[/color:39e8f5997e] Query_Depend.SQL.Add (´and extract(DAY FROM NASC) >= :Dia1 and extract(month FROM NASC) >= :Mes1 and extract(DAY FROM NASC) <= :Dia2 and extract(month FROM NASC) <=:Mes2´);
Query_Depend.SQL.Add(´order by NomeD, NASC´);
Query_Depend.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
Query_Depend.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
Query_Depend.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
Query_Depend.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
Query_Depend.Open;
end;
end;
end;
Me ajudem,
Obrigado Vivian
Estou com um probleminha. Estou fazendo um programa de relatório, onde quero que imprima somente titulares que fazem aniversario no seguinte intervalo de datas. Esta dando erro q eu nao sei o q é.
Banco: Cadastro.dbf
Delphi:6.0
Nasc: Campo nascimento
QR_Cad: Query do banco cadastro.
var
d1, d2, d3, m1, m2, m3, a1, a2, a3: word; {(onde d=dia, m=mes, a=ano e 1 = data inicial, 2=data final, 3=data da tabela)}
Begin
If (DtInicial.text = ´ / ´) or (DtFinal.text = ´ / ´) then
ShowMessage(´Informe o período que deseja consultar!´)
else
with QR_Cad do
begin
filtered := true;
decodedate(strtodate(DtInicial.text),a1,m1,d1);
decodedate(strtodate(DtFinal.text),a2,m2,d2);
first;
While not Eof do
Begin
decodedate(QR_Cad.fieldbyname(´NASC´).AsDateTime,a3,m3,d3);
if ((d3>=d1) and (m3>=m1)) and ((d3<=d2) and (m3<=m2)) then
begin
QR_Cad.Close;
QR_Cad.SQL.Clear;
QR_Cad.SQL.Add(´Select * from Cadastro WHERE NASC BETWEEN :DtInicial AND :DtFinal´);
QR_Cad.SQL.Add (´where extract(DAY FROM NASC) >= :Dia1 and extract(month FROM NASC) >= :Mes1 and extract(DAY FROM NASC) <= :Dia2 and extract(month FROM NASC) <=:Mes2´);
QR_Cad.SQL.Add(´order by Nome, NASC´);
QR_Cad.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
QR_Cad.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
QR_Cad.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
QR_Cad.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
QR_Cad.Open;
end;
end;
Acontece a mesma coisa quando tento fazer consulta dos dependentes. E aonde está em vermelho, é o lugar em q eu estou mais enrolada, pois o MSN do titular tem q ser igual ao MSN do dependente
Banco: Depend.dbf
Delphi:6.0
NascD: Campo nascimento
MSN: Matricula do titular
Query_depend: Query do banco cadastro.
var
d1, d2, d3, m1, m2, m3, a1, a2, a3: word; {(onde d=dia, m=mes, a=ano e 1 = data inicial, 2=data final, 3=data da tabela)}
Begin
If (DtInicial.text = ´ / ´) or (DtFinal.text = ´ / ´) then
ShowMessage(´Informe o período que deseja consultar!´)
else
with Query_Depend do
begin
filtered := true;
decodedate(strtodate(DtInicial.text),a1,m1,d1);
decodedate(strtodate(DtFinal.text),a2,m2,d2);
first;
While not Eof do
Begin
decodedate(Query_Depend.fieldbyname(´NASCD´).AsDateTime,a3,m3,d3);
if ((d3>=d1) and (m3>=m1)) and ((d3<=d2) and (m3<=m2)) then
Query_Depend.Close;
Query_Depend.SQL.Clear;
Query_Depend.SQL.Add(´Select * from Depend, Cadastro WHERE NASCD BETWEEN :DtInicial AND :DtFinal´);
[color=red:39e8f5997e]Query_Depend.SQL.Add(´and Cadastro.MS = Depend.MS´);[/color:39e8f5997e] Query_Depend.SQL.Add (´and extract(DAY FROM NASC) >= :Dia1 and extract(month FROM NASC) >= :Mes1 and extract(DAY FROM NASC) <= :Dia2 and extract(month FROM NASC) <=:Mes2´);
Query_Depend.SQL.Add(´order by NomeD, NASC´);
Query_Depend.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
Query_Depend.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
Query_Depend.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
Query_Depend.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
Query_Depend.Open;
end;
end;
end;
Me ajudem,
Obrigado Vivian
Viviankb
Curtidas 0
Respostas
Werlon Goulart
06/05/2003
Qual o Erro q da ???
Coloque aqui pra gente dar uma olhada...
Abraços
Werlon Goulart
Coloque aqui pra gente dar uma olhada...
Abraços
Werlon Goulart
GOSTEI 0
Coppola
06/05/2003
Velhinho,
Acrescente o comando:
Query_Depend.SQL.SaveToFile(´c:\windows\desktop\erro.text´);
demonstra os comandos de sql puro sem os comando do delphi, assim pode verifica os erros!!!
Acrescente o comando:
Query_Depend.SQL.SaveToFile(´c:\windows\desktop\erro.text´);
demonstra os comandos de sql puro sem os comando do delphi, assim pode verifica os erros!!!
GOSTEI 0
Ezdala
06/05/2003
pq não tenta fazer assim :
QR_Cad.Close;
QR_Cad.SQL.Clear;
QR_Cad.SQL.Add(´Select * from Cadastro´);
QR_Cad.SQL.Add (´where extract(day from NASC) >= :Dia1 and extract(month from NASC) >= :Mes1 and extract(day from NASC) <= :Dia2 and extract(month from NASC) <=:Mes2´);
QR_Cad.SQL.Add(´order by Nome, NASC´);
QR_Cad.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
QR_Cad.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
QR_Cad.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
QR_Cad.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
QR_Cad.Open;
QR_Cad.Close;
QR_Cad.SQL.Clear;
QR_Cad.SQL.Add(´Select * from Cadastro´);
QR_Cad.SQL.Add (´where extract(day from NASC) >= :Dia1 and extract(month from NASC) >= :Mes1 and extract(day from NASC) <= :Dia2 and extract(month from NASC) <=:Mes2´);
QR_Cad.SQL.Add(´order by Nome, NASC´);
QR_Cad.ParambyName(´Dia1´).AsInteger := StrToInt(Copy(DtInicial.Text,1,2));
QR_Cad.ParambyName(´Mes1´).AsInteger := StrToInt(Copy(DtInicial.Text,4,5));
QR_Cad.ParambyName(´Dia2´).AsInteger := StrToInt(Copy(DtFinal.Text,1,2));
QR_Cad.ParambyName(´Mes2´).AsInteger := StrToInt(Copy(DtFinal.Text,4,5));
QR_Cad.Open;
GOSTEI 0