2013-04-22 80 views
0

我有一個case語句是這樣的:無法理解一個case語句

CASE 
    WHEN purpose = "" THEN SET @sPurpose = "%%" 
    WHEN purpose IS NULL THEN SET @sPurpose = "%%" 
    ELSE SET @sPurpose = concat("%",purpose,"%"); 
END; 

,但是當我嘗試編譯的程序,它拋出這個錯誤:

SQL Error: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near 
'WHEN purpose IS NULL THEN SET @sPurpose = "%%" ELSE SET @sPurpose = co' at line 13 

我只是缺少一些語法的東西?

回答

4

這裏是做了正確的方式,

SET @sPurpose = CASE 
        WHEN purpose = "" THEN "%%" 
        WHEN purpose IS NULL THEN "%%" 
        ELSE concat("%",purpose,"%") 
       END; 
+1

這確實結束了工作。非常感謝! – smarble 2013-04-22 23:50:48

+0

@smarble不用客氣':D' – 2013-04-22 23:53:00