IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_gen_bizwrklink_before_all]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_gen_bizwrklink_before_all]
GO
create procedure [dbo].[mps_gen_bizwrklink_before_all](
@cmpid int,
@bizid int
)
as
begin
declare @ord2tag int 
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
declare @sql nvarchar(2000) 
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
declare c1 cursor LOCAL FORWARD_ONLY READ_ONLY for
select distinct  ws_id  from mps_flowwork,mps_flowworkstatus  where   wrk_bizid=@bizid and ws_swrkid=wrk_id   
open c1
FETCH NEXT FROM c1 INTO @ord2tag 
WHILE (@@FETCH_STATUS = 0)
BEGIN
if (dbo.checkprocedure(@tbname+'_'+convert(varchar(10),@ord2tag)+'_wrklink_before')=0 and 
dbo.mps_sys_checkkeywords('wrk.beforelinkapply',@ord2tag,0,'','')<>0) 
begin
set @sql = 'drop procedure '+@tbname+'_'+convert(varchar(10),@ord2tag)+'_wrklink_before' 
execute(@sql) 
end
if (dbo.mps_sys_checkkeywords('wrk.beforelinkapply',@ord2tag,0,'','')=0) 
exec mps_gen_bizwrklink_before @cmpid ,@bizid ,@ord2tag 
 FETCH NEXT FROM c1 INTO @ord2tag 
END
CLOSE c1
DEALLOCATE c1
end