MySQL Case problem

caseMySQL

I am trying to run a SQL code (I use MySQL). What I want to do is to set DATE_REACT a value when the first condition is satisfied, and a different value when the first condition is not satisfied. The problem is that the first condition is executed always, even when it shouldn't. What I am doing wrong?

UPDATE BILLS
SET STATE = 2,
DATE_REACT =
CASE 
WHEN (DATE_EM <= CURTIME() <= ADDTIME(DATE_EM, '00:02:00')) THEN ADDTIME(CURTIME(), '00:13:00')
ELSE ADDTIME(DATE_REACT, '00:13:00')
END
WHERE STATE = 1;

Best Answer

You can't combine boolean expressions like that. Try it this way:

UPDATE BILLS
SET STATE = 2,
DATE_REACT =
CASE 
WHEN (DATE_EM <= CURTIME() AND CURTIME() <= ADDTIME(DATE_EM, '00:02:00')) THEN ADDTIME(CURTIME(), '00:13:00')
ELSE ADDTIME(DATE_REACT, '00:13:00')
END
WHERE STATE = 1;