Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting query results - multiple columns

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
I have the following query:
Code:
<CFQUERY NAME=&quot;GetYourMeetings&quot;
			DATASOURCE=&quot;#Application.Datasource#&quot;
			DBTYPE=&quot;ODBC&quot;>
			SELECT	ReserveRoomID,ReserveRoomStart,RoomName
			FROM	ReserveTable,
			        RoomTable
			WHERE	ReservePersonID = '#Cookie.User.ID#'
			GROUP BY ReserveRoomID,RoomName,ReserveRoomStart
			ORDER BY RoomName,ReserveRoomStart DESC
	</CFQUERY>
These could be in any order in the database, but when I display them, I want them grouped together by RoomName in descending order(since the most popular room is at the end of the alphabet), and sorted by ReserveRoomStart within RoomName in ascending order. How do I do this? Thanks a lot! You people are the best!
Calista :-X
Jedi Knight,
Champion of the Force
 
Is this what you mean:

<CFQUERY NAME=&quot;GetYourMeetings&quot;
DATASOURCE=&quot;#Application.Datasource#&quot;
DBTYPE=&quot;ODBC&quot;>

SELECT ReserveRoomID,ReserveRoomStart,RoomName
FROM ReserveTable, RoomTable
WHERE ReservePersonID = '#Cookie.User.ID#'
GROUP BY ReserveRoomID,RoomName,ReserveRoomStart
ORDER BY RoomName DESC, ReserveRoomStart
</CFQUERY>

This will first order the query in Descending order by RoomName and then order the items (that have the same RoomName) by ReserveRoomStart in Ascending Order. - tleish
 
Thanks! That worked! I thought I had tried that, and got a syntax error, but I must have done something else wrong. Calista :-X
Jedi Knight,
Champion of the Force
 
Follow up question: The sort works, except, for example, it puts 3 PM before 11 AM for meetings on a given day. I assume this is due to the fact that the dates are stored as text fields rather than as date/time objects. I ran into this on a previous application, and found I could not store date/time objects as a list, and for this application, the dates must be in a list. Unless someone knows how to store date/time objects as a list in an Access datbase? Any ideas? Thanks a lot! Calista :-X
Jedi Knight,
Champion of the Force
 
The simplest solution to that would be to store the times in 24 Hours:

Normal Time = 24 Hour Time
11 AM = 11
3 PM = 15 - tleish
 
Thanks! That was a simple solution. I'm not sure why I didn't try that earlier. Oh, well. KISS, right? Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top