select com subselect

Firebird

05/08/2005

Ola amigos!!!!


tenho a seguinte procedure

FOR SELECT CLIENTES.CODIGO,
CLIENTES.NOME,
(select sum(movimento.total) from movimento where movimento.cod_cliente = clientes.codigo and movimento.situacao = 0) as deb,
(select sum(movimento.total) from movimento where movimento.cod_cliente = clientes.codigo and movimento.situacao = 3) as cre

FROM CLIENTES

INTO :R_CODIGO,
:r_nome,
:r_deb,
:r_cre
DO
BEGIN
if (:r_cre is null) then
begin
r_sit = ´´;
r_cre = 0;
r_total = :r_deb - :r_cre;
end
if ((:r_deb is not null) and (:r_cre is not null)) then
begin
r_sit = ´´;
r_total = :r_deb - :r_cre;
end
if (:r_deb is null) then
begin
r_sit = ´C´;
r_deb = 0;
r_total = :r_cre;
end

suspend;
END

funcionando perfeitamente, mas eu gostaria de adicionar mais um campo da tabela de movimentos (data_emissao between :data1 and :data2) , mas todas as minhas tentativa foram em vão.
Como posso solucionar o problema


Obrigado


Uiliangurjon

Uiliangurjon

Curtidas 0

Respostas

Afarias

Afarias

05/08/2005

(select sum(movimento.total) from movimento where movimento.cod_cliente = clientes.codigo and movimento.situacao = 0
and data_emissao between :data1 and :data2) as deb

e repete para cre


T+


GOSTEI 0
POSTAR