0
I’m trying to generate a query in VS2015 with Linq (here, I exemplified in SQL, to speed up my tests right in the database) that returns the data grouped and counted from 6 months ago, it happens that in some of the months there is no data so it does not appear in the result.
What I get:
total | data
 2      06/2017
 4      08/2017
 18     11/2017
As expected:
total | data
 2      06/2017
 0      07/2017
 4      08/2017
 0      09/2017
 0      10/2017
 18     11/2017
My query
    SELECT COUNT(Curso.ID_VENDA) as total, FORMAT(MAX(Venda.DATA),'MM/yyyy') AS data 
    FROM Curso 
    INNER JOIN Venda ON Curso.ID_VENDA = Venda.ID_VENDA
    INNER JOIN Produto ON Curso.ID_PRODUTO = Produto.ID_PRODUTO
    WHERE Produto.ID_CATEGORIA = 8
    AND Venda.DATA > dateadd(m, -6, getdate() - datepart(d, getdate()) + 1) 
    GROUP BY (YEAR(Venda.DATA) * 100) + MONTH(Venda.DATA)
    ORDER BY MAX(Venda.DATA) ASC
Has anyone experienced a similar case?
Hello, thank you, but had tried it. Produces the same initial result.
– ATT