Order by doesn't work in MS SQL
Posted on 2010-09-04
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) )"