IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_mod_program_content]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_mod_program_content]
GO
 
CREATE procedure [dbo].[mps_mod_program_content](
@ptid int,
@pt_caption nvarchar(200), 
@pt_category nvarchar(100), 
@pt_subcategory nvarchar(100), 
@pt_createtable int,
@pt_note nvarchar(500), 
@pt_icon varchar(200),
@pt_querytime int ,
@pt_share int,
@pt_hidemenu int,
@pt_hidemenu_mobile int,
@pt_merge int,
@pt_widget int 
)
as
begin
declare @s1 varchar(200) 
declare @s0 varchar(200) 
set @s1 = @pt_icon 
declare @i int 
declare @cmpid int 
set @i = CHARINDEX('|',@s1) 
if (@i>0)
begin
set @s0 = substring(@s1,@i+1,200) 
set @s1 = SUBSTRING(@s1,1,@i-1) 
end else 
begin
set @s0 = '' 
end 
if (@s1='_none_')
begin
set @s1 = '_none_' 
set @s0 = '_none_' 
end 
if (@s1='') set  @s1 = '_none_' 
if (@s0='') set  @s0 = '_none_' 

update  mps_programtype 
set pt_caption=case when @pt_caption='_none_' then pt_caption else @pt_caption end ,
pt_category=case when @pt_category='_none_' then pt_category else @pt_category  end ,
pt_subcategory=case when @pt_subcategory='_none_' then pt_subcategory else @pt_subcategory  end , 
pt_createtable=case when @pt_createtable=-999999999 then pt_createtable else @pt_createtable  end ,
pt_note=case when @pt_note ='_none_' then pt_note else @pt_note  end , 
pt_icon=case when @s1='_none_' then pt_icon else @s1 end,
pt_icon0=case when @s0='_none_' then pt_icon0 else @s0 end,
pt_querytime=case when @pt_querytime=-999999999 then pt_querytime else @pt_querytime end,
pt_share=case when @pt_share=-999999999 then pt_share else @pt_share  end,
pt_hidemenu=case when @pt_hidemenu=-999999999 then pt_hidemenu else @pt_hidemenu  end,
pt_hidemenu_mobile=case when @pt_hidemenu_mobile=-999999999 then pt_hidemenu_mobile else @pt_hidemenu_mobile  end,
pt_merge=case when @pt_merge=-999999999 then pt_merge else @pt_merge end,
pt_widget=case when @pt_widget=-999999999 then pt_widget else @pt_widget end,
pt_updatetime=getdate() 
where pt_id=@ptid 

if (@s0<>'' and @s0<>'_none_')
  begin
  declare @cat nvarchar(200) 
  select top 1 @cmpid=pt_cmpid,@cat = pt_category from mps_programtype where pt_id=@ptid 
  update mps_programtype set pt_icon0=@s0 where pt_cmpid=@cmpid and pt_category=@cat 
  end 
  
end