I am trying to see the profit by each month in SQL. However, I have multiple "Julys" and can't seem to separate them into different years. This is the query I am trying.
select
concat(datename(year, o.orderdate), ' ', datename(month, o.OrderDate)) [Month],
sum((t.StandardPrice - t.TotMaterialCost) * ol.OrderedQuantity) [Total Profit]
from
Temp_V t, OrderLine_T ol, Order_T o
where
t.ProductID = ol.ProductID
and ol.OrderID = o.OrderID
group by
o.OrderDate
I am getting the correct output, but for instance, it says July 2017 in two different rows instead of July 2017 and then July 2018. (Which is what I want it to say). I think it is an error with Concat()
.