im learning how to use the SELECT CASE but i don't understand very well, here is the code:
SET @vgls=1;
SET @lgls=1;
SET @st=SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis" END;
SELECT @st;
It gives me the following error:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to you MySQL server version for the right syntax to use near 'SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vg' at line 1
You need to use SELECT ... INTO
SELECT
...
INTO var_name [, var_name]]
instead of set
to assign the result of a SELECT to a variable. So this should do it:
SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis" END
INTO @st;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With