views:

24

answers:

2

I have two fields

start_time

end_time -> can be null

Now, depending on this I needs to differentiate between three states

Scheduled in future, Currently running Completed in past

Since mysql IF operator can not be nested, (Or I cant find an easy way to nest them), I cant find how to get the three state status.

A: 

you can use nested if in function , if its help you ,

http://dev.mysql.com/doc/refman/5.0/en/if-statement.html

Can you please add the query you tried to run?

Haim Evgi
A: 

Seems like you don't necessarily need to nest anything (pseudocode):

IF CURTIME()< start_time THEN SET mystate = 1;
ELSEIF CURTIME()> end_time THEN SET mystate = 3;
ELSE SET mystate = 2;
END IF;
LesterDove
untested (as pseudocode tends to be..)
LesterDove
change now to CURTIME()
Derek Adair
just to spruce up your psuedocode =)
Derek Adair