4
I have 3 tables in my database, CUSTOMERS, DISTRIBUTORS and EXPORT and I have a production order table where I take the customer type (Distributor, customer or export) and the ID of each of them. the question is: has as I put a if
in the select
, to be able to join the 3 tables with the production order? type like this:
if (tipocliente == CLIENTE)
select CamposDaTabela from OrdemDeProduçao inner join Cliente
if (tipocliente == Distribuidor)
select select CamposDaTabela from OrdemDeProduçao inner join Distribuidor
if (tipocliente == exportaçao)
select CamposDaTabela from OrdemDeProduçao inner join Exportaçao
It would be possible to do so within the same sql?
opa Emerson was exactly that... but now another little problem... can happen that the typoclient is null ... has to display the null tbm??
– Douglas
Yes, just do one more SELECT, add it with UNION. In this case, as the client type is NULL ,you will not JOIN with any table. I will edit my answer to contemplate this case.
– Emerson JS
Modified response, check.
– Emerson JS
good i tried here and gave this message: Message 205, Level 16, Status 1, Line 1 All queries Combined using a UNION, INTERSECT or EXCEPT Operator must have an Equal number of Expressions in their target lists.
– Douglas
This means that the 4 selects must return the same number of fields. Even, these fields have to be of the same type of data. Otherwise you cannot use UNION. If you cannot correct the error change your question and place the new SELECT to make it easy.
– Emerson JS
is pq no select do null is a field unless the fact of not joining with another... would have like me to create an empty field in select hr just to be equal??
– Douglas
Let’s go continue this discussion in chat.
– Douglas
Response edited by adding the null field in the last SELECT. It could also be an empty string, or a 0, depending on the type of data used in the other 3 SELECTS. Check.
– Emerson JS
Ahhh gave it right ... vlw msm face vdd thanks
– Douglas