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

create procedure [dbo].[sys_sql_log] (
@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='log')
select @script= @preblank + 'insert into sys_log(log_userid,log_time,log_biztype,log_bizid,log_objid, log_msg)' + char(13) +
@preblank + '      values(@useruid,getdate(),@thisbiztype,@thisbizid,@thiskeyval,@functionname)'

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

end