I need to set up a query that brings the total sales of each month from a table called sales.SalesOrderHeader
, but I'm not getting it. In this table there is a field OrderDate
which is the date of sale and TotalDue
is the value of the sale. This is my attempt:
select a.Year, a.Month
from
(
select distinct cast(year(orderdate) as varchar) + '_' +
case when month(OrderDate) < 10 then '0' else '' end + cast(month(OrderDate)as varchar) as Year_Month,
sum(TotalDue) as Total
From sales.SalesOrderHeader
group by month(OrderDate), OrderDate
) a
group by a.Month
order by 1