2011-11-30 144 views
0

我有與CASE聲明在此過程中的麻煩:MySQL的Case語句不起作用

DELIMITER // 
CREATE PROCEDURE getRowsByHourHalfday(xhour smallint) 
BEGIN 
    SET @twelveless = xhour - 12; 
    SELECT CASE 
      WHEN (xhour, > 11) THEN SET @realhour = (xhour - 12); 
      ELSE SET @realhour = xhour; 
    END CASE; 
    SET @first = @realhour * 60; 
    SET @next = @first + 59; 
    SELECT * FROM mydb.halfday WHERE minutepart BETWEEN @first AND @next; 
END // 
DELIMITER ; 

這是我想做的僞代碼:

if hour > 11 then 
    set newhour = hour - 12; 
    set first = newhour * 60; 
else 
    set first = hour * 60; 
endif 
select * from halfday where minutepart between first and (first + 60); 
+0

@亞當這個社區有時很迂腐...... – batman

回答

3

代替您的SELECT CASE聲明,直到END CASE,您應該擁有以下內容:

SET @realhour = CASE WHEN xhour > 11 THEN xhour - 12 ELSE xhour END CASE