Error The multi-part identifier "..." could not be bound

1

I'm trying to do the following select and it returns me the error The multi-part identifier "..." could not be bound in ImportaContratoAux.ContratoId

select AreaReclamacao.Descricao from AreaReclamacao 
inner join Contrato on Contrato.Id = ImportaContratosAux.ContratoId
inner join ImportaContratosAux on ImportaContratosAux.EmpresaId = AreaReclamacao.EmpresaId 
where Contrato.Id = '4100001124'
    
asked by anonymous 25.04.2018 / 19:49

1 answer

3

The error is because you are trying to access a field not yet mapped in join

In your first join you try to access ImportaContratosAux.ContratoId that is only being loaded in the second join to query should be:

select 
    AreaReclamacao.Descricao 
from AreaReclamacao 
    inner join ImportaContratosAux  on ImportaContratosAux.EmpresaId    = AreaReclamacao.EmpresaId 
    inner join Contrato             on Contrato.Id                      = ImportaContratosAux.ContratoId
where Contrato.Id = '4100001124'

See that the ImportaContratosAux is first loaded to then join with Contrato

    
25.04.2018 / 19:54