Good morning,
I have a query that is returning only the months with sales consumption, which should be the correct one. But now a blessed user wants me to come back every month, even those who have not had sales. How do I return as zero including what is being deleted in the query? rs.
Follow the code below:
SELECT Substring(C5_EMISSAO, 1, 6) AS EMISSAO,
Sum(C6_QTDVEN - C6_QTDENT) AS PERDA
FROM SC5010 SC5 WITH (NOLOCK)
INNER JOIN SC6010 SC6 WITH (NOLOCK)
ON C6_FILIAL = '01'
AND C6_NUM = C5_NUM
AND C6_PRODUTO = '6020210'
AND SC6.D_E_L_E_T_ = ' '
LEFT JOIN SD2010 SD2 WITH (NOLOCK)
ON D2_FILIAL = '01'
AND D2_PEDIDO = C5_NUM
AND D2_COD = C6_PRODUTO
AND D2_SERIE != 'R'
AND SD2.D_E_L_E_T_ = ' '
LEFT JOIN SF2010 SF2 WITH (NOLOCK)
ON F2_FILIAL = '01'
AND F2_DOC = C5_NOTA
AND F2_SERIE = C5_SERIE
AND SF2.D_E_L_E_T_ = ' '
WHERE C5_FILIAL = '01'
AND Substring(C5_EMISSAO, 1, 6) BETWEEN '201507' AND '201606'
AND C5_MODAL = '2'
AND C5_NOTA != ' '
AND SC5.D_E_L_E_T_ = ' '
GROUP BY Substring(C5_EMISSAO, 1, 6)
ORDER BY Substring(C5_EMISSAO, 1, 6) DESC
And this is the current payback:
As you can see, skip a few months. Remember that LOSS can be zeroed but in these months had sales (which does not appear in this query).
I need to bring every month of the range contained in Where
If someone has the light at the end of the tunnel, thank you
Hugs!