Last post Mar 29, 2018 09:26 AM by Deepak Panchal
Mar 27, 2018 03:46 AM|Ashraf007|LINK
Select Distinct isnull(sum(OrderQty),0) as OrderQty,DATENAME(MONTH,(OrderDate)) as [Months] from OrderTable Group By DATENAME(MONTH,(OrderDate))
I need to sort the above data using calendar month ascending .... Say Apr,May,June,July,Aug,Sep,Oct ... Now its shows in Apr,Aug,May,June etc
Mar 27, 2018 06:40 AM|vahid bakkhi|LINK
please try below query :
select *, case Months
when 1 then 'January'
when 2 then 'February'
when 3 then 'March'
when 4 then 'April'
when 5 then 'May'
when 6 then 'June'
when 7 then 'July'
when 8 then 'August'
when 9 then 'September'
when 10 then 'October'
when 11 then 'November'
when 12 then 'December'
Select Distinct isnull(sum(OrderQty),0) as OrderQty,DATEPART(Month, OrderDate) as [Months]
GROUP BY DATEPART(Month, OrderDate)
ORDER BY DATEPART(Month, Months) ASC
Mar 29, 2018 09:26 AM|Deepak Panchal|LINK
Try to refer example below.
Data in a table looks like below when fetching normally.
SELECT * FROM [dbo].[Emp1]
order by DATEPART(mm,CAST([MONTH]+ ' 1900' AS DATETIME)) asc