I'm trying to create a stored procedure to get the sums of values in a column, broken down by month over a year. What I've got looks like this:
select sum(n_colinches) from tbl_articles where dt_date between '09/01/2001' and '09/30/2001'
union
select sum(n_colinches) from tbl_articles where dt_date between '10/01/2001' and '10/31/2001'
union
"
"
select sum(n_colinches) from tbl_articles where dt_date between '08/01/2002' and '08/31/2002'
Of course the problem is that it returns NULL values for date periods that don't exist yet, so in this example it's only returning a couple of rows. Is there a better way to do this, or at least a way to fix it where it returns rows for each month even if the value would be NULL for that month?
select sum(n_colinches) from tbl_articles where dt_date between '09/01/2001' and '09/30/2001'
union
select sum(n_colinches) from tbl_articles where dt_date between '10/01/2001' and '10/31/2001'
union
"
"
select sum(n_colinches) from tbl_articles where dt_date between '08/01/2002' and '08/31/2002'
Of course the problem is that it returns NULL values for date periods that don't exist yet, so in this example it's only returning a couple of rows. Is there a better way to do this, or at least a way to fix it where it returns rows for each month even if the value would be NULL for that month?