0
I want to make a select that selects all customers and next create two columns a carrier call and another supplier and in each of them mark yes or no.
Ex:
Código Nome Fornecedor Transportadora
01 João Sim Não
02 Maria Não Sim
I have the selects:
-- carrier schedule:
select TraCod TR from T0055 TR, T0158 A where A.CliCod = TR.TraCod
-- supplier table
select * from T0185 F, T0158 A WHERE A.CliCod = F.ForCod
-- client table
select CliNom, CliReG, Clicgc, CliCgc2, CliNascCon, CliCid, CliCodUnf,
CliEnd, CliNum, CliBai, CliComple, CliCep, CliEmail, CliFon, CliFonCel
FROM T0158
You can make a
LEFT JOIN
with each table and check if theid
table to the right isNULL
. If it’s because you’re not a carrier/supplier– fernandosavio
have some example?
– Felipe Michael da Fonseca
That’s the idea. https://www.db-fiddle.com/f/vjKyzwygEgV2dMoEpijw4t/0
– fernandosavio
ok , but how to do in sql server?
– Felipe Michael da Fonseca
If I’m not mistaken MSSQL Server just use
LEFT OUTER JOIN
or instead ofLEFT JOIN
. The concept is the same in any relational database.– fernandosavio
@Felipemichaeldafonseca Are the columns that relate the tables correct in the examples? For example, the Tracod column is a foreign key in table T0055, pointing to the respective client?
– José Diz