Home > Enterprise >  If else in Mysql, how to declare constants in mySQL
If else in Mysql, how to declare constants in mySQL

Time:04-15

SET @Name1 = 'YES'; If @Name1 ='YES' select 2 from dual else Select 3 from dual;

what is wrong in above statements

CodePudding user response:

show this:

SET @Name1 := "YES";
SELECT IF(@Name1 = "YES", 2,3) AS VAL;

You can also do the init in 1 statement like this:

SELECT IF(@Name1 = "YES", 2,3) AS VAL, field1, field2
FROM yourTable
CROSS JOIN(SET @Name1 := "YES") AS init
WHERE ......;
  • Related