Complicated subquery

Complicated subquery

Post by alexandre michelo » Thu, 05 Dec 2002 02:32:23



Hi,

I have a table with events and a beginning date.
I want to retrieve the event for today (unique) and find out if we are
before or after the event...

For the second part, I have no problem (supposing we have only one event):
IF   (SELECT DATEDIFF(mi, T_EVENTS.StartTime, GETDATE())
  FROM T_EVENTS) < 0
-- before the event
ELSE IF  (SELECT DATEDIFF(mi, T_EVENTS.EndTime, GETDATE())
  FROM T_EVENTS) > 0
-- after event
ELSE
-- during the event

But when I try to select the event for today, I can't figure out how to
insert it in the statements above... :(

I try using the fact that :
SELECT event_id, DATEDIFF(d, StartTime, GETDATE())  as CurrentEvent
FROM T_EVENTS

has CurrentEvent = 0 for the today event, but can't go on further... :(
When I try
SELECT event_id, DATEDIFF(d, StartTime, GETDATE())  as CurrentEvent
FROM T_EVENTS
WHERE CurrentEvent = 0
I have an error message... :(

Anyway to do it ? Any help would be greatly appreciated.

Thank you,

    Alexandre.

 
 
 

Complicated subquery

Post by Alejandro Mes » Thu, 05 Dec 2002 02:47:54




-- This version will not use any index on StartTime

FROM T_EVENTS

or


FROM T_EVENTS

AMB

 
 
 

Complicated subquery

Post by alexandre michelo » Thu, 05 Dec 2002 18:31:23


Thank you very much...