3
Good morning,
I have a query that is only returning the months with sales consumption, which should be correct. Only now a blessed user wants me to return every month, including those who have no sales. How do I return to zero including what is being deleted in the query? rs.
Follows code:
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 comeback:
As you can see, they skip a few months. Remembering that the LOSS can be zero but in these months had sale (that does not appear in this consultation).
I need to bring every month of the break contained in Where
If anyone has the light at the end of the tunnel,
Hugs!
Very interesting Cantoni. I will take a look at the link that passed and do some tests. I need to see if the application of this concept can gain me a few seconds of performance. Thank you very much !
– Caio César Henrique