Wednesday, 15 April 2015

if else in mysql query

if else in mysql query

if-else in mysql works in the same way as it works in other programming languages.

Query example


delimiter $
CREATE PROCEDURE check_if (p_year INT)

BEGIN
declare res varchar(30);

IF p_year < 1000 THEN

set res = 'less than 1000';

ELSE

set res = 'greater than 1000;

END IF;

select res;
END$
delimiter ;



In the above PROCEDURE if p_year value is less than 1000 it  set res = 'less than 1000 
other wise it set res = 'greater than 1000;

No comments:

Post a Comment