Error: Multi-part identifier could not be associated

Asked

Viewed 7,134 times

1

I’m trying to execute the following command:

SELECT * FROM pendencia, cliente
LEFT JOIN servico ON pendencia.id_pendencia = servico.id_pendencia
LEFT JOIN cidade  ON cliente.id_cidade = cidade.id_cidade
WHERE cliente.id_cliente = pendencia.id_cliente AND servico.ativo = 1

And SQL Server returns me the following error:

Message 4104, Level 16, Status 1, Line 2 Multi-part identifier "pendencia.id_pendencia" could not be associated.

I don’t know where I’m going wrong, someone can tell me what’s wrong?

Follows the bank’s schematic:

Esquema do banco

  • 1

    I’m not sure, but maybe it has something to do with you mixing JOINs with , when listing the tables. Try placing the table cliente as INNER JOIN (and part of WHERE would go to the ON of that JOIN).

1 answer

2

Correct your JOIN or use with comma or use with JOIN, LEFT JOIN

Example:

SELECT * FROM pendencia a
JOIN cliente b ON a.id_cliente = b.id_cliente
LEFT JOIN servico c ON a.id_pendencia = c.id_pendencia
LEFT JOIN cidade d ON a.id_cidade = d.id_cidade

So I believe it is better and not to accuse the error, the problem is in its syntax.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.