CREATE PROCEDURE dbprincipal.spaltamodjfmarcas(  in iid int,
  in ibrand varchar(255),
  in ilogo varchar(255),
  in icode varchar(255)
  
)
    NO SQL
begin
declare ExisteMarca  int;
set ExisteMarca = (select idjfmarcas from fjmarcas where id  = iid);
if (ExisteMarca  > 0) then
	UPDATE fjmarcas
		SET 
		brand = ibrand,
		logo = ilogo,
		code = icode 
	WHERE idjfmarcas=ExisteMarca;
else
	INSERT INTO fjmarcas 
		(id, brand, logo, code)
	VALUES(iid, ibrand,ilogo, icode);
	set ExisteMarca = (select last_insert_id());
end if; 
select ExisteMarca;
end;
