I need help to create a select, I have 4 tables (commission, person, request, request). So I need to bring all people and their goal values even though I do not have values yet in order. I made a select problem that it does not return the person when it has no request to that person.
I want it to return for example: name of person / goal / valuereached
My code is like this until now:
SELECT
[PESSOA].[Fantasia] AS PESSOA,
[METAS].[MetaValorMinimoBase] AS META,
SUM(ISNULL(PDV_PedidoItemValorTotal,0)) AS Valor
FROM COM_METAS
FULL JOIN PESSOA ON METAS.MetaRepCod = PESSOA.Codigo
LEFT JOIN PEDIDO ON PESSOA.Codigo = PEDIDO.PedidoRepresentante
LEFT JOIN PEDIDOITEM ON PEDIDO.PedidoCodigo = PEDIDOITEM.PedidoCodigo
WHERE PEDIDO.PedidoExcluido = 'N' and
PEDIDO.PedidoTipoMovimentoCodigo IN (1,5,6) AND
PEDIDO.PedidoSituacao IN ('A','B','O','T','E')AND
PEDIDO.PedidoDataEmissao BETWEEN '01/06/2018' AND '05/06/2018'
GROUP BY
[PESSOA].[Fantasia],
[METAS].[MetaValorMinimoBase]
Order by [PESSOA].[Fantasia]
RETURN:
JOÃO |60000 |697569
PEDRO |240000 |1374417
MARIA |60000 |67995
FRANCISCO |200000 |2376976
ZÉ |NULL |23423
ROMARIO |20000 |NULL
I want you to bring me other people who have goals even if they have no value.
It even returns people with a null goal, but I want them to return those with null value or 0 as well.