DELIMITER $$
drop procedure if exists
`Promoter_Save`$$
create PROCEDURE `Promoter_Save`(IN `pUserId` BIGINT, IN `pPromoterCode` VARCHAR(50), IN `pPromoterTypeId` BIGINT , IN `pActive` BIT)
BEGIN
IF not exists (select * from promoter where UserId=pUserId) THEN
insert into promoter
(
UserId,
PromoterCode,
PromoterTypeId,
Active
)
values
(
pUserId,
pPromoterCode,
pPromoterTypeId,
pActive
);
ELSE
update promoter
set
PromoterCode=pPromoterCode,
PromoterTypeId=pPromoterTypeId,
Active=pActive
where UserId=pUserId;
END IF;
select last_insert_id();
END$$
DELIMITER ;