Select comparing in Where 2 columns of different tables

Asked

Viewed 22 times

0

I’m trying to set up a consult but it’s not bringing anything.

SELECT EMP, COD, VEV, SEQ, TIP, NUM, EMI, VEN, DTR, GRU, PRO, QTD, PVE, TOT, FAT, COM, COO, REF, VAR, hcli.NOM as "VENDEDOR",
hemp.enc from hcov 
    INNER JOIN hcli ON hcov.COD = hcli.COD
    JOIN hemp ON hemp.cod = hcov.emp 
WHERE (hcli.NOM NOT LIKE '%COOPERATIVA%')
AND (DTR >= date '2020-01-01')
AND (COD NOT IN (24545 ,10368 ,13149, 10448, 11041, 30610, 6834) )
AND (GRU <> 266 OR GRU <> 269 OR GRU <> 272)
AND ( (VEV <> 37125) AND (COO NOT IN (987209, 23631, 927500, 22763, 38736 ) ) )
AND (num = 84831 and emp = 24)
AND (hemp.enc <> hcov.cod)

The problem is in the last line of the consultation, because when I take it out it works.. but I need it for comparison. I’m actually riding the wrong way?

Below an image of the result without the last query line > inserir a descrição da imagem aqui

  • 1

    Any comparison with "null" returns as "false" a solution is something of the type AND ((Hemp.Enc <> hcov.Cod) or (hcov.Cod is null)) but needs to define well what to do in these cases , inform the DBMS because the treatment of null (nvl COALESCE isnull)

  • but how I would then make this comparison and bring in the query only if COD is different from ENC ??

  • put this way that you spoke worked out... AND ((Hemp.Enc <> hcov.Cod) or (Hemp.Enc is null))

No answers

Browser other questions tagged

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