MySQL if then/ case statement
there! I'm writing mysql script in mySQl Front 4.1.
I have problem with if then, case statements.I have next code:
set @prodID = -1;
select @prodID = productID
from partid_to_productid
where PartID= 8;
case @prodID
WHEN NULL then select 0;
else select 3;
end case
Front doesn't want to execute开发者_运维百科 it. Why? Can someone explain me what is wrong here?
The SELECT
goes outside the CASE
:
SELECT
CASE @prodID
WHEN NULL THEN 0
ELSE 3
END;
Actually, that's not returning 0 for me as I expect when testing. Instead try:
SELECT CASE WHEN @prodID IS NULL THEN 0 ELSE 3 END;
精彩评论