CREATE PROCEDURE `rtest`.`inpair` (in id int,in lev int)
BEGINDECLARE r int;
DECLARE l int;
select rman into r from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());
select lman into l from tblmancount where regId=id and level=lev and month = month(curdate()) and year =year(curdate());
if r insert into tblpair values(id,lev,r,month(curdate),year(curdate)); elsei insert into tblpair values(id,lev,l,month(curdate),year(curdate)); end if; END