Blue Streak (an*******@msn.com) writes:
I have the following query that I run that pulls up the count of the
number of orders of a product.
SELECT Product, Count(Product) AS Total
FROM Orders_View
GROUP BY Product, Year([DateOpened]), Month([DateOpened])
HAVING (((Year([DateOpened]))=2004) AND ((Month([DateOpened]))=10))
ORDER BY Product;
This query is fine but the COUNT() function only coughs-up the non-zero
results. How can I get this query to cough-up the zero counts as well
for all products listed in the Product table?
It is always adviceable for this type of question to post:
1) CREATE TABLE statement for your tables (and in this case also the view)
2) INSERT statements with sample data.
3) The desired output given the sample data.
That permits anyone answering your question to easily cut and paste into
to Query Analyzer and develop a tested solution.
The solution suggested by David Rowland should give you the desired
result, but it may not be that performant.
An alternative is to explorr GROUP BY ALL, but with out the table and
view definitions, I can't test.
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp