2
I’ve researched but I can’t find what I need.
I have a chart where I have a record of debt and credit releases. These values are in the 'value' field. But I want to display this field in two columns, one for debit and one for credit.
I got:
SELECT L.REGISTRO, C.CODCADASTRO, CRE.VALOR AS CREDITO, DEB.VALOR AS DEBITO
FROM CADASTRO C
JOIN LANCAMENTOS L ON C.CODCADASTRO = L.CODFAVORECIDO
LEFT JOIN LANCAMENTOS CRE ON CRE.REGISTRO = L.REGISTRO AND CRE.TIPOLANCAMENTO = 0
LEFT JOIN LANCAMENTOS DEB ON DEB.REGISTRO = L.REGISTRO AND DEB.TIPOLANCAMENTO = 1
I want to add one more column to add the two together, and that’s where I can’t. The column that has the debit I get NULL in credit and the same happens with the credit column. The sum of the records of these columns is coming NULL.
CRE.VALOR AS CREDITO, DEB.VALOR AS DEBITO, (CRE.VALOR + DEB.VALOR) AS SOMA
So my problem is: How to sum the values of fields per record where a field is NULL?
Att.
Do you want to add a value with NULL? type 1+null??
– Fleuquer Lima
Yes, this is because a LEFT JOIN generated a NULL value in one of the columns and I was unable to perform the sums.
– Lindomar Lemos