Delete all items that have at least one Null value

Asked

Viewed 52 times

-1

I am needing to do a query that DOES NOT return the Ids of contracts that have ANY installments like Null, in the example below I need it to return empty, because the ID contract 666666 has at least one null installment, even if the 3° line has an integer.

Remove null lines with not exists or not in would be no problem, but with these commands the query would still return to 3° line

select contrato.IdContrato as ID, parcela.ValorParcela as Parcela
left join parcelas on parcelas.IdContrato = contrato.IdContrato
where contrato.IdContrato = 666666

The query provides fields like:
ID | Plot
666666 | null
666666 | null
666666 | 200

2 answers

1


Arthur, I think you can use not exists. Here is a suggestion for testing:

select contrato.IdContrato as ID, parcela.ValorParcela as Parcela
left join parcelas on parcelas.IdContrato = contrato.IdContrato
where 
    contrato.IdContrato = 666666 and 
    not exists
    (
        select 1 from parcelas as s 
        where 
            s.IdContrato = contrato.IdContrato and
            s.ValorParcela is null
    )

I hope it helps

0

You can use AND to meet all the conditions.

Would be:

where contrato.IdContrato = 666666 and parcela.ValorParcela !=  null
  • But in that case he would be keeping the third line yet, no?

Browser other questions tagged

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