Question : sql : mm-yy from date time stamp

can someone point out how im approaching this wrong

i am using the below query to show the sum of qtys sold by month/year

but when i order by the date, it is then all muddled up, eg its starts at Sept

how can i achive what i need and still sort by current date desc



Code Snippet:
1:
2:
3:
4:
select product, sum (quantity) as QTY,(datename(mm,dated) + datename(yyyy,dated)) as mmyy
from scheme.opsadetm
group by product, (datename(mm,dated) + datename(yyyy,dated))
order by mmyy desc

Answer : sql : mm-yy from date time stamp

Why don't you separate the date into year and month.

select product, sum(quantity) as QTY, Month(dated) as Month, Year (dated) as Year
FROM scheme.opsadetm
GROUP BY product, Year, Month
ORDER BY Year DESC, Month DESC
Random Solutions  
 
programming4us programming4us