IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_do_execute_job_auto2]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_do_execute_job_auto2]
GO
create procedure [dbo].[mps_do_execute_job_auto2](
@cmpid int ,
@branchid int ,
@userdpid int,
@useruid int ,
@userotid int , 
@bizordwrk varchar(50),
@cbizid int ,
@cordid bigint 

)
as 
begin
set nocount on
declare @bizid int  
declare @wrkid int 
declare @ordid bigint 
declare @i int 
declare @s varchar(100)
declare @s1 varchar(100)
set @s = @bizordwrk 
set @i = CHARINDEX(',',@s) 
set @bizid = 0 
set @ordid = 0 
set @wrkid = 0 
if (@i>0) 
begin
set @bizid = CONVERT(int,substring(@s,1,@i-1)) 
set @s = substring(@s,@i+1,LEN(@s)-@i) 
set @i = CHARINDEX(',',@s) 
if (@i>0) 
begin
set @ordid = CONVERT(bigint,substring(@s,1,@i-1)) 
set @s = substring(@s,@i+1,LEN(@s)-@i) 
set @wrkid = CONVERT(int,@s) 
end 
end 

if (@ordid=0) set @ordid=@cordid 
if (@bizid=0) set @bizid=@cbizid 

if (@branchid=-1) 
begin
select top 1 @branchid= cu_bcid , @userdpid=cu_dpid , @userotid=cu_otid 
from mps_login with(nolock) where cu_id=@useruid 
end 
exec mps_do_execute_job_auto 
@cmpid  ,
@branchid  ,
@userdpid ,
@useruid  ,
@userotid  , 
@bizid  ,
@ordid ,
@wrkid
 
set nocount off
end