Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Complicated Query


Message #1 by "David Smith" <DJSmith@m...> on Thu, 17 May 2001 13:00:25 -0500
The sort mechanism itself can't query the data, so you're going to have to 
work in a query. Do a comparison of the two time fields and return the 
largest into a column, then just sort on the single time column. 

SELECT EarlistTime = 
	CASE
		WHEN TimeStarted < TimeEnded THEN TimeStarted
		ELSE TimeEnded
	END, ...
FROM ...

Regards.

> I have a table that records the "Time Started" and Time Ended" for every
> record in the table.  I need to be able to sort the table so that it is
> ordered by both of the time records.  I.E.  If the earliest record is for
> the time began on one record, but the next record is by the time ended on
> another record, then I need them in that order.
> 
> I am able to order by start time or end time, but need to know if it is
> possible to order by time, regardless if it is the start time or the end
> time.
> 
> Can anyone help me.
> 
> 

  Return to Index