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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Question 1

Status
Not open for further replies.

azzazzello

Technical User
Jan 25, 2005
297
US
I have a Table which has, among other fields, 3 TIME fields. 1 of them is a basically a start time (starttime), and the other 2 are end times of an event (endtime1 and endtime2). I won't get into the details of why there are 2 end times, but suffice it to say that they may both have values, only one of them may have a value (while the other is NULL), or neither may have a value. My query is selecting records where EITHER one of them has a value (because I can use either). Here is my dilhema - I need to do something like this:

SELECT Sum(endtime1 - starttime) as total,... FROM ... WHERE (endtime1 IS NOT NULL OR endtime2 IS NOT NULL) .... GROUP BY total.

But what if endtime1 is NULL and endtime2 is the one that contains the actual time? Is there some way I can quickly determine which is NOT null and use that one in my calculation?
 
use

Code:
coalesce(endtime1,endtime2)

that will return the first non null value of the colums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top