IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[sys_sql_act_err]') AND type = 'P')
DROP PROCEDURE [dbo].[sys_sql_act_err]
GO

create procedure [dbo].[sys_sql_act_err] (
@parseid int,
@preblank varchar(50),
@script varchar(1000) output
)
as
begin
declare @optype varchar(20),@ttable varchar(20),@funvarname varchar(20),@functionname varchar(50)
select @optype=optype,@ttable=ttable
from sys_sql_inf
where parseid=@parseid

select @funvarname=funvarname,@functionname=functionname
from sys_sql_fun
where parseid=@parseid

if (@optype='wfaction')
if (@funvarname is not null and @funvarname='add')
select @script=@preblank + 'select @operation=@operation +''' + @functionname + ''''
else
select @script=@preblank + 'select @operation=''' + @functionname + ''''
else if (@optype='wferror')
if (@funvarname is not null and @funvarname='add')
select @script=@preblank + 'select @errorinfo=@errorinfo +''' + @functionname + ''''
else
select @script=@preblank + 'select @errorinfo=''' + @functionname + ''''

if (@script is null)
set @script=''
else
select @script=@script + char(13)

end