[firebase-br] Duvida em Left Outer Join

Carvalho carvalho em invitro.com.br
Qui Mar 10 15:50:59 -03 2005


Caro Eduardo,

No Interbase 6 eu não posso utilizar First 1.

Eu também não quero que retorna nada( isso no exemplo de dados abaixo), onde
eu tenho um registro matando o outro.

Eu só quero que traga registros de débitos que ainda não possuam registros
de crédito em uma determinada data e de um determinatdo cliente

Ok?

Obrigado,

Carvalho

----- Original Message -----
From: "Eduardo Jedliczka" <eduardo em gerasoft.com.br>
To: "FireBase" <lista em firebase.com.br>
Sent: Thursday, March 10, 2005 3:33 PM
Subject: Re: [firebase-br] Duvida em Left Outer Join


dá uma olhada assim...

Select MF.Numero, MF.NumDoc, MF.NumParcela, MF.VrDeb, MF.Data,
MF.DtVenc, MF.CodCli, C.Nome, C.Cidade, C.ContaCtb
from MovFinanc MF
Left Outer Join Cliente C on C.Codigo = MF.CodCli
where not exists
(select First 1 MF2.Numero from MovFinanc MF2
 where
  MF2.Numero = MF.Numero
  and MF2.NumDoc = MF.NumDoc
  and MF2.NumParcela = MF.NumParcela
  and MF2.CodCli = MF.CodCli
  and MF2.vrDeb is Null )
and MF.Data <= '01/31/2005' and MF.VrDeb is not Null
and MF.CodCli = 1640
Order by C.Nome

Se não funcionar, faz assim para consultar: (e veja o resultado do
totalCredito)

Select MF.Numero, MF.NumDoc, MF.NumParcela, MF.VrDeb, MF.Data,
MF.DtVenc, MF.CodCli, C.Nome, C.Cidade, C.ContaCtb,
(select Sum(MF2.vrCred) from MovFinanc MF2
 where
  MF2.Numero = MF.Numero
  and MF2.NumDoc = MF.NumDoc
  and MF2.NumParcela = MF.NumParcela
  and MF2.CodCli = MF.CodCli
  and MF2.vrDeb is Null) as TotalCredito
from MovFinanc MF
Left Outer Join Cliente C on C.Codigo = MF.CodCli
and MF.Data <= '01/31/2005' and MF.VrDeb is not Null
and MF.CodCli = 1640
Order by C.Nome

[s]

==========================
Eduardo Jedliczka
Gerasoft Informática
Apucarana - Pr
==========================

----- Original Message -----
From: "Carvalho" <carvalho em invitro.com.br>
To: "FireBase" <lista em firebase.com.br>
Sent: Thursday, March 10, 2005 2:48 PM
Subject: Re: [firebase-br] Duvida em Left Outer Join


> Caro Eduardo,
>
> Segui o seu exemplo com algumas modificações, mas mesmo assim continua
> retornando um registro.
>
> Veja como eu fiz:
>
> Select MF.Numero, MF.NumDoc, MF.NumParcela, MF.VrDeb, MF.Data,
> MF.DtVenc, MF.CodCli, C.Nome, C.Cidade, C.ContaCtb from MovFinanc MF
> Left Outer Join Cliente C on C.Codigo = MF.CodCli
>
> where not exists
> (select MF2.Numero from MovFinanc MF2
>  where
>   MF2.Numero = MF.Numero
>   and MF2.NumDoc = MF.NumDoc
>   and MF2.NumParcela = MF.NumParcela
>   and MF2.CodCli = MF.CodCli and MF2.vrcred is not null)
>
> and MF.Data <= '01/31/2005' and MF.VrDeb is not Null
> and MF.CodCli = 1640
> Order by C.Nome
>
> Continua retornando assim:
>
> DtEmissao     Cliente    VrDebito   VrCredito   Vencimento    Numero
Parcela
> 16/12/2004    1640         490,80                      14/01/2005
49201
> 1
>
> a tabela está assim:
>
> DtEmissao     Cliente    VrDebito   VrCredito   Vencimento    Numero
Parcela
> 16/12/2004    1640         490,80                      14/01/2005
49201
> 1
> 16/12/2004    1640                           490,80    20/01/2005
49201
> 1
>
> Eu não quero que retorna nada.
>
> Detalhe utilizo Interbase 6 com IBX
>
>
>
>
>
> Carvalho, seu problema é de lógica...
>
> O Left Outer Join, vai trazer os que tem e os que não tem lançamentos...
> hehehe...
>
> O Mais certo seria utilizar um "Exists"...
>
> Select dados_da_nota from tabela A
> where not exists ( select first 1 qualquercoisa from tabela B where
> A.dtEmissao=B.dtEmissao and A.OutrosCampos=B.outrosCampos)
>
> Naturalmente o select acima não funciona, mas dá para entender...
>
> [s]
>
> ==========================
> Eduardo Jedliczka
> Gerasoft Informática
> Apucarana - Pr
> ==========================
>
> ----- Original Message -----
> From: "Carvalho" <carvalho em invitro.com.br>
> To: <lista em firebase.com.br>
> Sent: Thursday, March 10, 2005 12:37 PM
> Subject: [firebase-br] Duvida em Left Outer Join
>
>
> In Vitro Diagnóstica S/A
> Caros colaboradores,
>
> Bom dia!
>
> Estou tentando fazer um select para retornar somente registros em aberto
> baseado no campo DtEmissao e que não tenha um registro de crédito e
somente
> de débito.
>
> Um registro de débito não está mais em aberto quando eu tenho um outro
> registro de crédito fechando a fatura do cliente.
>
> Vejam um exemplo:
> DtEmissao     Cliente    VrDebito   VrCredito   Vencimento    Numero
> Parcela
> 16/12/2004    1640         490,80                      14/01/2005
49201
> 1
> 16/12/2004    1640                           490,80    20/01/2005
49201
> 1
>
> O Select abaixo está me retornando o seguinte:
>
> DtEmissao     Cliente    VrDebito   VrCredito   Vencimento    Numero
> Parcela
> 16/12/2004    1640         490,80                      14/01/2005
49201
> 1
>
> E na verdade não deveria retornar nada, pois eu tenho um registro matando
o
> outro.
>
> O que está errado?
>
> Select MF.Numero, MF.NumDoc, MF.NumParcela, MF.VrDeb, MF.DtEmissao,
> MF.DtVenc, MF.CodCli, C.Nome, C.Cidade, C.ContaCtb from MovFinanc MF
> Left Outer Join Cliente C on C.Codigo = MF.CodCli
>
> Left Outer Join MovFinanc MF2 on MF2.Numero = MF.Numero
> and MF2.NumDoc = MF.NumDoc and MF2.NumParcela = MF.NumParcela
> and MF2.CodCli = MF.CodCli and MF2.VrCred is not null
>
> where MF.DtEmissao <= '01/31/2005' and MF.VrDeb is not Null
> and MF.CodCli = 1640 and MF2.VrCred is null
>
> group by MF.Numero, MF.NumDoc, MF.NumParcela, MF.VrDeb, MF.DtEmissao,
> MF.DtVenc, MF.CodCli, C.Nome, C.Cidade, C.ContaCtb
>
> Order by C.Nome
>
> Grato pela colaboração.
>
>
> --------------------------------------------------------------------------
--
> ----
>
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.bavs.com.br
> Para editar sua configuração na lista, use o endereço
> http://mail.firebase.com.br/mailman/listinfo/lista_firebase.com.br
>
>
>
>
>
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.bavs.com.br
> Para editar sua configuração na lista, use o endereço
> http://mail.firebase.com.br/mailman/listinfo/lista_firebase.com.br
>
>
>
>
>


----------------------------------------------------------------------------
----


______________________________________________
FireBase-BR (www.firebase.com.br) - Hospedado em www.bavs.com.br
Para editar sua configuração na lista, use o endereço
http://mail.firebase.com.br/mailman/listinfo/lista_firebase.com.br





----------------------------------------------------------------------------
----


______________________________________________
FireBase-BR (www.firebase.com.br) - Hospedado em www.bavs.com.br
Para editar sua configuração na lista, use o endereço
http://mail.firebase.com.br/mailman/listinfo/lista_firebase.com.br







Mais detalhes sobre a lista de discussão lista