Avatar of mlg101
mlg101
Flag for United States of America asked on

Order by doesn't work in MS SQL

I have the following SQL statement that returns the correct rows, but they are out of order. They are the days of the week, but I want them in the correct order, such as Sunday, Monday, Teuesday, etc.  The order by on this statement does not return any rows. If I take the order by off, it returns the correct rows, just not in the order I would like. Here it is:

Dim strDayQuery As String = "Select id, InstrumentID, TeacherID, DATENAME(dw , EventStart) As Day, DATEPART(dw, EventStart) As Day2 FROM Events WHERE id IN (SELECT MAX(id) FROM Events WHERE InstrumentID = @InstrumentID And TeacherID = @TeacherID And Available <> 'False' Group by DATENAME(dw , EventStart) Order by DATEPART(dw, EventStart) )"
Microsoft SQL Server

Avatar of undefined
Last Comment
Mohit Vijay

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
apresence

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Mohit Vijay

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61