r/SQL•
mac-0

[T-SQL] Summing values by month, and returning 0 for months with no records?

Let's say I have the following really simple table:

DateAmount
1/1/16100

If I were to run the following query:

 SELECT Month([Date]), SUM([Amount]) FROM Table GROUP BY Month([Date])

I'd get the following results:

MonthSum of Amount
1100

But what I really want are my results to look like this:

MonthAmount
1100
20
30
40
50
60
70
80
90
100
110
120

How do I tell the query to return a result for all values in MONTH = 1-12

Posted Jan 5, 2017, 11:00 PM UTC

25
Loading comments…