IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_alarm]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_alarm]
GO
CREATE procedure [dbo].[mps_save_alarm](
@almidint,
@alm_titlenvarchar(100),
@alm_objtypevarchar(30),
@alm_objidint,
@alm_objid2int,
@alm_categorynvarchar(100),
@alm_tmpidint,
@alm_tmpcaptionnvarchar(100),
@alm_tobizidint,
@alm_biztitlenvarchar(100),
@alm_createmodeint,
@alm_sqlnvarchar(MAX) 
)
as
begin
set nocount on
update mps_alarm set 
alm_title=case when @alm_title='_none_' then alm_title else @alm_title end ,
alm_objtype=case when @alm_objtype='_none_' then alm_objtype else @alm_objtype end ,
alm_objid =case when @alm_objid=-999999999 then alm_objid else @alm_objid end ,
alm_objid2=case when @alm_objid2=-999999999 then alm_objid2 else @alm_objid2 end ,
alm_category=case when @alm_category='_none_' then alm_category else @alm_category end ,
alm_tmpid=case when @alm_tmpid=-999999999 then alm_tmpid else @alm_tmpid end ,
alm_tmpcaption=case when @alm_tmpcaption='_none_' then alm_tmpcaption else @alm_tmpcaption end ,
alm_tobizid=case when @alm_tobizid=-999999999 then alm_tobizid else @alm_tobizid end ,
alm_biztitle=case when @alm_biztitle='_none_' then alm_biztitle else @alm_biztitle end ,
alm_createmode=case when @alm_createmode=-999999999 then alm_createmode else @alm_createmode end ,
alm_sql=case when @alm_sql='_none_' then alm_sql else @alm_sql end  
where alm_id=@almid 
declare @objtype varchar(20) 
declare @cmpid int 
declare @bizid int 
select @objtype=alm_objtype ,@cmpid=alm_cmpid , @bizid=alm_objid 
from mps_alarm where alm_id=@almid 
if (@objtype='ebs') 
begin
exec mps_gen_ebsalarm @cmpid,@almid 
end else 
begin
exec mps_gen_bizalarm @cmpid , @bizid 
end 
set nocount off
end