jeudi 24 mars 2016

if else endif statement in mysql

Here is my working SQL procedure.

create procedure check_budget_sp(in department_name varchar(20), in salary decimal(8,2), out res varchar(1)) 
   begin
     declare current_budget_helper decimal(12,2) ;
 declare max_budget_helper decimal(13,2) ;
     select cur_budget , max_budget  into current_budget_helper , max_budget_helper from department where dept_name=check_budget_sp.department_name;
         if max_helper>(cur_budget + check_budget_sp.salary)  then
           set res="F";
          else
           set res="T";               
         end if;
  end

My problem is(was) the following.I was trying to use if else statement without end if and MySQL always gave me syntax error.Even though this code works I just did not like the concept that you "must" inform the system with writing end if to specify that if-else statement is over.Is there any other way to accomplish the same code without using end if?I was thinking about writing two separate if clauses instead of using if-else but I still had a syntax error

Aucun commentaire:

Enregistrer un commentaire