IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_flowwork_auto]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_flowwork_auto]
GO
create procedure [dbo].[mps_save_flowwork_auto](
@cmpid int ,
@wrkid int , 
@interval int ,
@unit varchar(10),
@webservice varchar(100),
@starttime datetime ,
@sql nvarchar(max) 
) as
begin
declare @name varchar(100)
if (@unit<>'分钟' and @unit<>'小时' and @unit<>'天') 
begin
set @interval = 0 
set @unit = ''
set @starttime = '2199-01-01' 
end 

begin
update mps_flowwork set wrk_auto2_interval = @interval  ,
wrk_auto2_unit = @unit ,
wrk_auto2_webservice = @webservice ,
wrk_auto2_starttime = @starttime  
where wrk_id=@wrkid 
if (not exists (select 1 from mps_extsqljs with(nolock) where cd_objid=@wrkid and cd_name='wrk.wrkauto' )) 
begin
insert into mps_extsqljs(cd_name,cd_objid,cd_objid2,cd_text)
values('wrk.wrkauto',@wrkid,0,@sql )
end else 
begin
update mps_extsqljs set cd_text=@sql where cd_objid=@wrkid and cd_name='wrk.wrkauto' 
end 
if (LEN(@sql)<10) 
begin
delete mps_extsqljs where cd_objid=@wrkid and cd_name='wrk.wrkauto'  
end 
-- 业务单的自动化，是在业务单生效后才能有效，因此这里是不需要加任务的。 
end
end