IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_extsqljs]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_extsqljs]
GO
CREATE procedure [dbo].[mps_save_extsqljs] 
@objid int ,
@objid2 int ,
@cdname varchar(50),
@text text 
 as
begin
declare @cdid int 
declare @ss varchar(100) 
set @ss = convert(varchar(100),@text) 
select top 1 @cdid = cd_id from mps_extsqljs where cd_objid=@objid and cd_objid2=@objid2 and cd_name=@cdname 
set @cdid = isnull(@cdid,0) 
if (@cdid=0)
begin
   if (len(@ss)>5) 
   begin
insert into mps_extsqljs(cd_objid,cd_objid2,cd_name,cd_text) 
select @objid , @objid2 , @cdname , @text 
end 
end else 
begin
if (len(@ss)>5) 
begin
update mps_extsqljs set 
cd_text = @text 
where cd_id=@cdid 
end else 
   begin
   delete mps_extsqljs where cd_id=@cdid 
   end 
end 
end