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.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
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
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
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.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
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