1

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?

Roman
  • 565
  • 1
  • 10
  • 27
  • the anwser is what @Michel says or: consider that CASE is an operator (it returns one value) but it do not control flow, nor excutes statments (as you put SELECTs). if you need flow control replace with IFs – Saic Siquot Jul 12 '11 at 15:15

1 Answers1

4

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;
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Maybe you know how to write in mysql something like this `if @partID is null then insert into partid_to_productid (value1, value2)` – Roman Jul 12 '11 at 15:13