March 22, 2023 at 12:24 pm
SELECT BusinessEntityID,FirstName,MiddleName,LastName,
YEAR(OrderDate) AS OrderYear,
DATENAME(MM,OrderDate) AS OrderMonth
FROM Person.Person Pp
INNER JOIN Sales.Customer Sc
ON Sc.PersonID=Pp.BusinessEntityID
INNER JOIN Sales.SalesOrderHeader Ss
ON Sc.CustomerID=Ss.CustomerID
ORDER BY BusinessEntityID,YEAR(OrderDate),MONTH(OrderDate)
Month is not sorted properly.
Could you please let me know what could be the issue
291 Gustavo NULL Achong 2011 August
291 Gustavo NULL Achong 2012 January
291 Gustavo NULL Achong 2012 April
291 Gustavo NULL Achong 2012 July
291 Gustavo NULL Achong 2012 October
291 Gustavo NULL Achong 2013 January
March 22, 2023 at 12:36 pm
Define 'properly'. It looks OK to me, unless you want to sort on the name of the month, rather than its ordinal.
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
March 22, 2023 at 12:39 pm
Yep, looks right to me too.
----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore Roosevelt
The Scary DBA Author of: SQL Server 2022 Query Performance Tuning, 6th Edition and SQL Server Execution Plans, 3rd Edition
Product Evangelist for Red Gate Software
March 22, 2023 at 12:44 pm
got it thanks for the clarification . I should have observed i am sorting based on year and month.
thanks hguys
March 22, 2023 at 12:59 pm
Also, why not just use
ORDER BY BusinessEntityID, OrderDate
?
It might perform better.
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
March 22, 2023 at 4:16 pm
Also, why not just use
ORDER BY BusinessEntityID, OrderDate?
It might perform better.
+1000
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply