IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_up_messagetemplate]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_up_messagetemplate]
GO

-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE procedure [dbo].[mps_up_messagetemplate]
@mp_id int ,
@cmpid int,
@mp_name varchar(30) ,
@mp_caption nvarchar(50) ,
@mp_gzhincode varchar(50) ,
@mp_dayuincode varchar(50) ,
@mp_gzhtext nvarchar(4000) ,
@mp_qyhtext nvarchar(4000) ,
@mp_dingtext nvarchar(4000) ,
@mp_dayutext nvarchar(4000) ,
@mp_pctext nvarchar(4000) ,
@mp_gzhid int ,
@mp_qyhid int ,
@mp_dingid int ,
@mp_dayuid int ,
@mp_gzhpreview nvarchar(4000) ,
@mp_qyhpreview nvarchar(4000) ,
@mp_dingpreview nvarchar(4000) ,
@mp_dayupreview nvarchar(4000) ,
@mp_pcpreview nvarchar(4000) ,
@mp_scope varchar(20),
@mp_sign varchar(50)
AS
BEGIN
SET NOCOUNT ON;

update ebs_kernel.dbo.pub_messagetemplate set

mp_name=case when @mp_name='_none_'       then mp_name       else @mp_name end,
mp_caption=case when @mp_caption='_none_'    then mp_caption    else @mp_caption end,
mp_gzhincode=case when @mp_gzhincode='_none_'  then mp_gzhincode  else @mp_gzhincode end,
mp_dayuincode=case when @mp_dayuincode='_none_' then mp_dayuincode else @mp_dayuincode end,
mp_gzhtext=case when @mp_gzhtext='_none_'    then mp_gzhtext    else @mp_gzhtext end,
mp_qyhtext=case when @mp_qyhtext='_none_'    then mp_qyhtext    else @mp_qyhtext end,
mp_dingtext=case when @mp_dingtext='_none_'   then mp_dingtext   else @mp_dingtext end,
mp_dayutext=case when @mp_dayutext='_none_'   then mp_dayutext   else @mp_dayutext end,
mp_pctext=case when @mp_pctext='_none_'   then mp_pctext   else @mp_pctext end,

mp_gzhid=case when @mp_gzhid=-999999999    then mp_gzhid       else @mp_gzhid end,
mp_qyhid=case when @mp_qyhid=-999999999    then mp_qyhid       else @mp_qyhid end,
mp_dingid=case when @mp_dingid=-999999999   then mp_dingid      else @mp_dingid end,
mp_dayuid=case when @mp_dayuid=-999999999   then mp_dayuid      else @mp_dayuid end,

mp_gzhpreview=case when @mp_gzhpreview='_none_'    then mp_gzhpreview     else @mp_gzhpreview end,
mp_qyhpreview=case when @mp_qyhpreview='_none_'    then mp_qyhpreview     else @mp_qyhpreview end,
mp_dingpreview=case when @mp_dingpreview='_none_'    then mp_dingpreview     else @mp_dingpreview end,
mp_dayupreview=case when @mp_dayupreview='_none_'    then mp_dayupreview     else @mp_dayupreview end,
mp_pcpreview=case when @mp_pcpreview='_none_'    then mp_pcpreview     else @mp_pcpreview end,

mp_scope=case when @mp_scope='_none_'      then mp_scope       else @mp_scope end,
mp_sign =case when @mp_sign='_none_'      then mp_sign       else @mp_sign end

where mp_id=@mp_id and mp_cmpid=@cmpid
exec mps_gen_wrk_message_all  @cmpid

END