IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_event_indexvalue_after]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_event_indexvalue_after]
GO
create procedure [dbo].[mps_save_event_indexvalue_after]
(
@cmpid int
) as
begin

set nocount on

declare @psql nvarchar(max) 

declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for
  select evt_id  from mps_bizevent with(nolock) 
  where evt_cmpid=@cmpid  and len(evt_sql)>10 
  open status1
  declare @evt_id int
  
  set @psql = '' 
  FETCH NEXT FROM status1 INTO @evt_id 
  WHILE (@@FETCH_STATUS = 0)
  BEGIN
   set @psql='exec mps_save_event @evt_id,''_none_'',''_none_'',''_none_'' '
   exec sp_executesql @psql, N'@evt_id int', @evt_id  
   FETCH NEXT FROM status1 INTO @evt_id 
  END
  CLOSE status1
DEALLOCATE status1 


set nocount off 
end