Thursday, October 4, 2012

Return and Check exists in MySql Stored Procedure


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 ;

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...