THE INN-VISIBLE THE INN-VISIBLE - 3 months ago 9
MySQL Question

Why 'begin' keyword for if statement, is showing error in stored procedure. (mysql)?

begin
declare currentMonth int;
declare half int default 0;
set currentMonth = (select DATE_FORMAT(now(),"%m"));
if(currentMonth > 5)
**begin**
set half = 1
end


end;


This is screen shot of what error is shown


Showing me this error: MySQL server version for the right syntax to use near 'begin set half = 1; end select currentMonth into half' at line 6

Answer

Use into in select set is not uset

begin

declare currentMonth int;
declare half int default 0;

select DATE_FORMAT(now(),"%m") INTO @currentMonth;

if(currentMonth > 5) THEN
        set half = 1;
end if;

end
Comments