IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_alter_job_executor]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_alter_job_executor]
GO
create procedure [dbo].[mps_alter_job_executor](
@cmpid int , 
@useruid int,
@jbids varchar(8000),
@newcuid int ,
@reason nvarchar(200) 
) as
begin
set nocount on
if (@reason is null or @reason='' or @reason='_none_') set @reason = '' 
-- @jbids 100,200,300,320:23,....
declare @s varchar(8000) 
declare @s1 varchar(100) 
declare @s2 varchar(100) 
declare @i int 
declare @t table(jbid bigint, cuid int) 
set @s = @jbids 
while (@s>'') 
begin
set @i =CHARINDEX(',',@s) 
if (@i>0) 
begin
set @s1 = SUBSTRING(@s,1,@i-1) 
set @s = SUBSTRING(@s,@i+1,LEN(@s)-@i) 
end  else 
begin
set @s1 = @s 
set @s = '' 
end 
set @i =CHARINDEX(':',@s1) 
if (@i>0) 
begin
set @s2 = SUBSTRING(@s1,1,@i-1) 
set @s1 = SUBSTRING(@s1,@i+1,LEN(@s1)-@i) 
end  else 
begin
set @s2 = @s1 
set @s1 = '' 
end 
if (@s1='') set @s1 = CONVERT(varchar(10),@newcuid) 
insert into @t(jbid,cuid) 
values(convert(bigint,@s2),convert(int,@s1)) 
end 
update mps_job set jb_cuid=cuid , jb_executor=cu_callname  
from mps_login , @t 
where jb_id=jbid and cu_id=cuid and jb_wsid=0 
set nocount off 
end