Duvidas com SQL

Delphi

02/06/2004

Ola gente,

Estou precisando fazer uma query para saber quais os cliente que não compra em uma certa data.
Tenho a Tabela1 com os campos Dt_Venda, Cod_Clie e Tabela2 com dos dados dos clientes Cod_Clie.

se Alguém poder me ajudar


Walbert


Wcprog

Wcprog

Curtidas 0

Respostas

Ale.riopreto

Ale.riopreto

02/06/2004

o comando é o seguinte:

Tenho a Tabela1 com os campos Dt_Venda, Cod_Clie e Tabela2 com dos dados dos clientes Cod_Clie.


Select * from Tabela1
where Dt_Venda - Getdate() >= :dias

:dias -> parametro que vc ira passar na query antes de dar o open..

ex.

Query1.Close;
Query1.ParambyName(´dias´).asfloat:=60;
Query1.Prepare;
Query1.open;


GOSTEI 0
Adilsond

Adilsond

02/06/2004

select c.cod_clie,
       c.nom_clie,
       c....
from tabclie c
where not exists (select 1
                  from tabvend v
                  where v.cod_clie = c.cod_clie
                    and v.dt_venda not between :dtini and :dtfin)
order by c.nom_clie


ou

select c.cod_clie,
       c.nom_clie,
       c....
from tabclie c
where c.cod_clie not in (select distinct v.cod_clie
                         from tabvend v
                         where v.dt_venda between :dtini and :dtfin)
order by c.nom_clie



GOSTEI 0
Aroldo Zanela

Aroldo Zanela

02/06/2004

Colega,

Eu faria da seguinte forma:

SELECT * FROM TABELA1
INNER JOIN TABELA2
ON (TABELA1.cod_clie = TABELA2.cod_cli)
WHERE DATA_COMPRA <= :X_DATA



GOSTEI 0
POSTAR